'multer in express return mensage [MulterError: Unexpected field]
I've been trying to get this to work for several days, but I read the documentation for express and I can't get it to work
My code is as simple as possible, because I just want to try to upload an image.
const express = require('express');
const multer = require('multer');
const upload = multer({ dest: 'uploads/' })
var app = express();
app.post('/profile', upload.single('avatar'), (req, res) => {
});
app.listen(process.env.PORT || 3000, () => {
console.log(`Server start on port ${process.env.PORT || "3000"}`);
})
And I'm using Insomnia to test the file upload, maybe I'm not getting it because of the method I'm using, however, in Insomnia I create a new call in post method, and in Body I add it as "Multipart Form" , then I add a value in file and with the name "Photo", but when I send it always returns the same message.
MulterError: Unexpected field
at wrappedFileFilter (C:\work\uploadImage\node_modules\multer\index.js:40:19)
at Busboy.<anonymous> (C:\work\uploadImage\node_modules\multer\lib\make-middleware.js:115:7)
at Busboy.emit (events.js:400:28)
at Busboy.emit (C:\work\uploadImage\node_modules\busboy\lib\main.js:38:33)
at PartStream.<anonymous> (C:\work\uploadImage\node_modules\busboy\lib\types\multipart.js:213:13)
at PartStream.emit (events.js:400:28)
at HeaderParser.<anonymous> (C:\work\uploadImage\node_modules\dicer\lib\Dicer.js:51:16)
at HeaderParser.emit (events.js:400:28)
at HeaderParser._finish (C:\work\uploadImage\node_modules\dicer\lib\HeaderParser.js:68:8)
at SBMH.<anonymous> (C:\work\uploadImage\node_modules\dicer\lib\HeaderParser.js:40:12)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
