Answer the question
In order to leave comments, you need to log in
How can nodejs read the data that came from the client using formdat?
How to read the data correctly, and most importantly, from where in nodejs (Express framework) that come from the client?
if this data is some json, then everything is simple. All that I need is on req.body, but what if I use formdata and put, for example, a picture in binary format?
Here is the client code (react)
async function onSubmit() {
const fileFormData = new FormData();
fileFormData.append('file', file, file.name);
fileFormData.append('name', 'TEST_NAME');
const result = await Execute('file/upload', {
method: 'POST',
body: fileFormData,
headers: {
'CRU-Authorization': localStorage.getItem('login') || '',
'auth_token': localStorage.getItem('auth_token') || '',
}
});
console.log(result);
}
router.post("/upload", async function(request, response) {
console.log(request.body)
});
Answer the question
In order to leave comments, you need to log in
https://metanit.com/web/nodejs/10.1.php
https://github.com/expressjs/multer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question