I got an Object from multer that its name is files that has two properties : artworks and inspiration. I want to get the originalname of each property but when I run the code I just get artworks originalnames? How can I solve this problem?
{
artworks:
[ { fieldname: 'artworks',
originalname: 'Icon_OutdoorLeisure.png',
encoding: '7bit',
mimetype: 'image/png',
buffer:
<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 64 00 00 00 64 08 06 00 00 00 70 e2 95 54 00 00 00 09 70 48 59 73 00 00 0b 13 00 00 0b 13 01 ... >,
size: 1598 } ],
inspiration:
[ { fieldname: 'inspiration',
originalname: 'Icon_HealthWellness_Hovered.png',
encoding: '7bit',
mimetype: 'image/png',
buffer:
<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 64 00 00 00 64 08 06 00 00 00 70 e2 95 54 00 00 00 09 70 48 59 73 00 00 0b 13 00 00 0b 13 01 ... >,
size: 1986 } ] }
export const Orderfilsename = function (files) {
let result = JSON.parse(JSON.stringify(files));
for (var key in result) {
if (result.hasOwnProperty(key)) {
let result_2 = result[key].map((res) => {
const name = res.originalname.split('.')[0];
const fileExtName = extname(res.originalname);
const randomName = Array(4)
.fill(null)
.map(() => Math.round(Math.random() * 10).toString(10))
.join('');
return `${name}${randomName}${fileExtName}`;
});
return JSON.stringify(result_2);
}
}
};
const Orderfilsename = function (files) {
let names = []
for(let key in files) {
let groupNames = files[key].map(el => {
return el.originalname
})
names = [...names, ...groupNames]
}
return names
};
console.log(Orderfilsename(data))