I've solved the CASE!!
-Check if you have the same thing as i do:
My problem wasnt that backend does not receive the formData
, the problem was that fileFilter
does not receive formData
, because multer
does not offer req.body
nor req.file
with it, how to check if that is your problem? go to fileFilter
function, and log the body
, and then go to processImage
function and log the body, if it logs in processImage
, but not in fileFilter
, then you have my problem, if it doesnt log for both, I dont think that my solution will work for you
-How to solve this problem?
go to your front-end, appending data like this:
formData.append('file', values.file);
formData.append('textContent', 'textContent');
will not work, you must make the append function for file
field at the end, as below:
formData.append('textContent', 'textContent');
formData.append('file', values.file);
And your problem have been solved. Congrats!
simply because postman sends the data of the form as one piece, and the file field is at the end, while front end, you made file field first, so while multer
process the file field, it runs fileFilter
, so fileFilter
does not gets the body, nor the file, while when sending body first then file, the body gets processed, so fileFilter
Thanks for everyone.
By the way this case is answered before, but people who gets into this problem does not know that this is same problem as this.