0
votes

i've written my backend with NodeJS and my frontend with React.

I use redux and axios in frontend for push CRUD operations and i want to upload five mp3 files to backend with multer.

So i've set multer as the following code

const fileStorageImage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null, "audio");
    },
    filename: (req, file, cb) => {
        cb(null, new Date().toISOString() + "-" + file.originalname);
    }
});

app.use(multer({storage: fileStorageImage}).array('file', 20));

and set my route as the following

router.post("audios", (req, res, next) => {

    console.log(req.files)

}

So on my output i expect to see print my files uploaded, but otherwise my output was 'undefined'.

My question is: How can i upload multiple file on multer and get this file data from my router.post()?

NB = On frontend i use <input name="file" multiple />.

1

1 Answers

1
votes

Use multer in your route as middleware like

router.post("audios", multerconfig, (req, res, next) => {

     console.log(req.files)

}

Go here I have answered in detail to a question on this site