Answer the question
In order to leave comments, you need to log in
How to upload and store photos on server (React+Express+Mongo)?
How to transfer a photo from React to the server with subsequent storage there?
On the client, I get the object in which this file is stored
{title: "1", description: "2", photo: File(1240), authorLink: "5a718696b9a93f333bc282df", author: "123"}
axios
.post("http://localhost:8000/addPost", post, { withCredentials: true
})
app.post("/addpost", (req, res, next) => {
const post = new Post(req.body);
post.save(err => {
if (err) {
console.log(err);
res.end();
}
console.log("Сохранен " + post);
res.statusCode = 200;
res.json(post);
});
});
Answer the question
In order to leave comments, you need to log in
Use FormData to submit files:
const formData = new FormData();
formData.append('file', someFile);
axios.post('/uploadFile', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
The issue is resolved, I’ll add on my own - you can accept files on the server according to this instruction https://alligator.io/nodejs/uploading-files-multer...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question