Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload file on Express.js app

Tags:

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?

like image 806
Luca Marzi Avatar asked Apr 20 '15 11:04

Luca Marzi


People also ask

How do I upload files using Express?

Open the local page http://127.0.0.1:2000/ to upload the images. Select an image to upload and click on "Upload Image" button. Here, you see that file is uploaded successfully. You can see the uploaded file in the "Uploads" folder.

Can we upload file using JavaScript?

html file through a browser, the client will be able to upload a file to the server using Ajax and pure JavaScript. A pure JavaScript file uploader simplifies Ajax based interactions with the server.

How do I send files in express response?

sendFile() Function. The res. sendFile() function basically transfers the file at the given path and it sets the Content-Type response HTTP header field based on the filename extension.

How do I upload files to node JS Express server using Express fileUpload library?

Create Express Server const express = require('express'); const fileUpload = require('express-fileupload'); const cors = require('cors'); const bodyParser = require('body-parser'); const morgan = require('morgan'); const _ = require('lodash'); const app = express(); // enable files upload app.


1 Answers

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

like image 110
Xelz Avatar answered Oct 12 '22 01:10

Xelz