79220203

Date: 2024-11-24 13:53:28
Score: 3.5
Natty:
Report link

I've solved the CASE!!

For anyone who is getting this problem, please follow these EASY steps:

Steps:

-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!

Why does this problem happen?

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.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): How to solve
  • RegEx Blacklisted phrase (1.5): How to solve this problem?
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: The Khateeb Dev