24
votes

I'm developing a RESTful API for a mobile client application with the combination of Node.js, Express.js and Mongodb. Now I'm trying to handle the upload of the user profile image and I've found a module called "multer" (that is the one ecommended by express.js team itself) that allow the express.app to handle multipart/form-data requests. Now I need to test the app and, moreover, the upload function but I'm not able to simulate a http-form request (via postman chrome plugin). Multer returns this error:

[Error: Multipart: Boundary not found]

In fact, comparing an http-form request (which works) with a custom http request, the second one has not the Boundary header property.

What Boundary property is?

3

3 Answers

57
votes

If you are using Postman, you can try removing the Header: "Content-type": "multipart/form-data". I removed it and now it works.

14
votes

Boundary in a multipart form indicates some delimiter string separating text and binary data. You can do this in postman but it sounds like you aren't sending both file and text so postman maybe defaults to a regular form. do you see something like:

postman-form-multipart

If you click preview in postman you can see the boundary in the Content-type header and in the body.

7
votes

solutions:

1) don't specify the content-type at client

2) use the naming convention(imageUpload) in upload.single('imageUpload') same as field name