Skip to content Skip to sidebar Skip to footer

Empty Body Api Rest Express Node Js

I'm trying to make an API using express in nodejs. This api should get a request with a photo and post that photo to firebase storage. The main problem is that for some reason the

Solution 1:

you have to send an image from the front end in formData.

const data = new FormData();
data.append('myFile', 'Image Upload');

In back end use multer to upload file to server. first install multer by : npm i multer

const multer = require("multer");
//Configuration for Multerconst upload = multer({ dest: "public/files" });
app.post("/api/uploadFile", upload.single("myFile"), (req, res) => {
// Stuff to be added laterconsole.log(req.file);
});

Here is a proper Guide to upload file using multer express js

Post a Comment for "Empty Body Api Rest Express Node Js"