JosephM
JosephM

Reputation: 2935

Getting issue with upload file using multer

Uploading file using multer, here is my code

var multer  = require('multer');
var upload = multer({ dest: 'uploads/' });
app.post("/upload",upload.single('image'), api.uploadFile);

getting following error when uploading image file doing multi-part request

Error: Buffer.write(string, encoding, offset[, length]) is no longer supported
    at Buffer.write (buffer.js:742:11)
    at MultipartParser.initWithBoundary (D:\eclipse-workspace-oxy\ChatServer\node_modules\formidable\lib\multipart_parser.js:61:17)
    at IncomingForm._initMultipart (D:\eclipse-workspace-oxy\ChatServer\node_modules\formidable\lib\incoming_form.js:308:10)
    at IncomingForm._parseContentType (D:\eclipse-workspace-oxy\ChatServer\node_modules\formidable\lib\incoming_form.js:250:12)
    at IncomingForm.writeHeaders (D:\eclipse-workspace-oxy\ChatServer\node_modules\formidable\lib\incoming_form.js:129:8)
    at IncomingForm.parse (D:\eclipse-workspace-oxy\ChatServer\node_modules\formidable\lib\incoming_form.js:97:8)
    at D:\eclipse-workspace-oxy\ChatServer\node_modules\connect\lib\middleware\multipart.js:125:12

Upvotes: 1

Views: 558

Answers (2)

JosephM
JosephM

Reputation: 2935

Finally got the solution, need to add bodyParser for parse request bodies in a middleware.

var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

it will work for Url Encoded requests. For Multi-part request, need to add middle ware like multer.

Upvotes: 1

mjarraya
mjarraya

Reputation: 1226

Your stack trace shows that the problem comes from formidable, not multer.

A quick search on formidable's github open issues gives this.

Maybe try to run npm update.

Upvotes: 1

Related Questions