Problems encountered when using express to write and upload files
The front-end Axios and the back-end express use the multer
middleware. They always report the error of the server 500 when uploading. They repeatedly check the code and check the multer
documents, and finally find the problem.
No more nonsense, just go to the code:
Back end:
router.post('/upload',upload.single('img'),function(req,res,next){
console.log(req.file);
})
front end:
formdata.append('img',imgfile);
here, the name in upload.Single()
should be consistent with the field name in the front end formdata