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
Read More:
- Node.js Error: Cannot find module express [How to Solve]
- [Solved] nodejs Error: request entity too large
- [Solved] express-jwt Error: Error: jwt is not a function
- Node.js Error: Error: Cannot find module ‘express‘ [How to Solve]
- [Solved] express-jwt Error: Error: algorithms should be set
- How to Solve JS error: Unexpected end of JSON input,Unexpected token u in JSON at position 0
- How to Solve Nodejs error: cannot find module ‘. /application’
- [Solved] Node Create Express Project Error: Failed to lookup view “error“ in views directory
- [Weex]Error in creating project NPM: unable to load file D:\program files\nodejs\node_ global\ weex.ps1 Because scripts are not allowed to run on this system.
- [Solved] ajax Error: Uncaught SyntaxError: Unexpected end of JSON input
- [Solved] Uncaught SyntaxError: Unexpected token ‘<‘
- [Solved] Vue unit test syntax error: unexpected token ‘export‘
- [Solved] Webpack compile error: SyntaxError: Unexpected token =
- node.js yarn Error: SyntaxError: Unexpected string [How to Solve]
- error in ./node_modules/@lit/reactive-element/decorators/state.jsModule parse failed: Unexpected
- [Solved] React Startup Error at the First time :SyntaxError: Unexpected token
- Vue Import three.JS error: Unexpected token [How to Solve]
- error: Unexpected console statement (no-console) [How to Solve]
- [Solved] error: Unexpected console statement (no-console)
- ArcGIS API for JavaScript version 4. X updated and the project startup error: Module parse failed: Unexpected token(… …