Skip to content
Advertisement

How to rename file in Multer middleware to data I am sending in request

On a frontend I am generating unique ID for every order. Idea is to rename file which user uploads to orderId. Here is my request to server:

JavaScript

Here is the server code:

JavaScript

console.log(req.body) shows empty object in filename and orderId in app.post(). Here is how it looks:

JavaScript

So this cannot be done as far as I understand inside filename. How to deal with this situation? And is this even possible?

Advertisement

Answer

All I had to do, is to change order I am appending to formData.

Now this works:

JavaScript
Advertisement