1

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.