File object sending from frontend using react and formData I have manually made the file object looks like...
After uploading a file i am getting the object in multer and express-upload
console.log(req.files.productImages)
[{
"name": "galaxy-1.jpeg",
"data": {
"$binary": "/9j/4AAQSkZJRgABAQAAAQABAAD/2FasgasadagzxvADFCaBGRRXSADa0"
},
"size": 2895,
"encoding": "7bit",
"tempFilePath": "",
"truncated": false,
"mimetype": "image/jpeg",
"md5": "b7192406a75b765dd0582daa4807ca71"
}]
I want to get file object with label: value.
example:
[{
"label": "oxygen blue",
"name": "galaxy-1.jpeg",
"data": {
"$binary": "/9j/4AAQSkZJRgABAQAAAQABAAD/2FasgasadagzxvADFCaBGRRXSADa0"
},
"size": 2895,
"encoding": "7bit",
"tempFilePath": "",
"truncated": false,
"mimetype": "image/jpeg",
"md5": "b7192406a75b765dd0582daa4807ca71"
}]
Please help me to achieve this thing.
Afaik this is not possible as multer will either receive the file itself without any additonal custom properties and/or any text-fields present in the form-data request. But ... multer allows you to access both files and text-fields.
So assuming your request looks something like this:
and this server-side code:
Then the following will be logged to the console:
According to this github-issue multer preserves the order, so you could use the corresponding index of the files to find their labels.