multer
multer copied to clipboard
multer.array removes null items
When my endpoint receives an array of pictures, some elements can be null. My issue is multer ignores null values, and it's impossible to me to associate the index with the file.
Is there a way to do that? If needed I can update my frontend code.
Front:
const formData = new FormData();
this.form.pictures.forEach(player => {
formData.append('photos', player.picture);
})
await axios.post("/photos/upload", formData);
Payload example:
photos: false
photos: (binary)
photos: null
Back:
router.post(
"/photos",
multer({dest: uploadsPath + "/photos"}).array('photos', 6),
async (req, res) => {
console.log(req.files);
}
Result log:
[
{
fieldname: 'photos',
originalname: 'very-small.jpg',
encoding: '7bit',
mimetype: 'image/jpeg',
destination: 'backend/public/uploads/photos',
filename: 'ddf16ac69d5288370b599401a87363fd',
path: 'backend/public/uploads/photos/ddf16ac69d5288370b599401a87363fd',
size: 20827
}
]