Currently, I am utilizing FormData in my VueJS FrontEnd to send images to my Express Server for storage in a Mongo DB using gridfs-stream and mongoose. Despite the image objects successfully reaching the server, I am struggling to access their key-value pairs.
Upon executing the following code:
let part = req.files
for (const prop in part) {
console.log('part.${prop} = ${part[prop]}')
}
The output I received was:
part.files[0] = [object Object]
part.files[1] = [object Object]
However, when attempting to access part.files[0], I encountered the following error:
TypeError: Cannot read property '0' of undefined
Below is the structure of the Object:
{ 'files[0]':
{ data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 48 00 48 00 00 ff db 00 43 00 08 06 06 07 06 05 08 07 07 07 09 09 08 0a 0c 14 0d 0c 0b 0b 0c 19 12 13 0f ... >,
name: 'e0ZnCwP.jpg',
encoding: '7bit',
mimetype: 'image/jpeg',
truncated: false,
size: 259454 },
'files[1]':
{ data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 48 00 48 00 00 ff c0 00 11 08 06 40 04 c8 03 01 22 00 02 11 01 03 11 01 ff c4 00 1f 00 00 01 05 01 01 01 ... >,
name: 'Me.jpeg',
encoding: '7bit',
mimetype: 'image/jpeg',
truncated: false,
size: 108021 } }
Thank you in advance for any assistance!