'I'm not able to get files in req.files when I call the api in nodejs reactjs
I'm sending array of files of image to NodeJs to upload them on AWS but I get no value only empty array of files when I console.log(req.files).
image:
[
File {name: 'Faateh Uni - function now() { [native code] }', lastModified: 1647858683757, lastModifiedDate: Mon Mar 21 2022 15:31:23 GMT+0500 (Pakistan Standard Time), webkitRelativePath: '', size: 12771, …},
File {name: 'Faateh Uni - function now() { [native code] }', lastModified: 1647858683766, lastModifiedDate: Mon Mar 21 2022 15:31:23 GMT+0500 (Pakistan Standard Time), webkitRelativePath: '', size: 411301, …},
File {name: 'Faateh Uni - function now() { [native code] }', lastModified: 1647858683769, lastModifiedDate: Mon Mar 21 2022 15:31:23 GMT+0500 (Pakistan Standard Time), webkitRelativePath: '', size: 36455, …}
]
This is how i created these files :
for (let index in contentImages) {
const contentImage = await fetch(contentImages[index]);
const contentImageBlob = await contentImage.blob();
const coverFile = new File(
[contentImageBlob],
`${submitValues.sourceName} - ${Date.now}`,
{ type: contentImageBlob.type }
);
image.push(coverFile);
}
This is nodejs:
app.post(
"/api/readingsources/new",
upload.array("image", 5),
(req, res) => {
const coverImage = req;
res.status(200).send("OK");
}
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
