Uploading files to express

Viewed 66

I want to upload files from a ReactJS app to an ExpressJS server.

My request is looking as follows:

Request headers

Request body

As you can see, the Content-Type header is set correctly, to allow files to be uploaded.

Now, in ExpressJS I have the following code in index.js:

    const express = require('express');
    const fileUpload = require('express-fileupload');

    const app = express();

    app.use(fileUpload({
        createParentPath: true
    }));
    app.use(express.json());

My output from a console.log(req.body) is as follows: Output

I get the same result when using multer. body-parser is deprecated, but using express.urlencoded({extended: true}) also gives the same result.

My expected output is just an object with the body and I expect req.files to contain the image. How would I go about fixing this?

0 Answers
Related