0

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.