这是一个简单的图像FileList。
Object.keys(pet).forEach((key) => {
if (key === "images") {
formData.append("images", pet[key]); //my fileList
} else {
formData.append(key, pet[key]);
}
});此FileList >>的Console.log

但是当我试图在后端访问相同的fileList时,它显示一个空数组...
const images = req.files;
console.log(images); // equals to []当我尝试这样做的时候:
const images = req.body.images;
console.log(images); // Returns this: [object FileList].当我将相同的端点与Postman完美结合使用时...
发布于 2021-11-24 23:49:46
刚刚发现发生了什么.我正在传递一个对象数组,它包含一个FileList,它是一个星形数组,所以它永远不会工作……
Object.keys(pet).forEach((key) => {
if (key === "images") {
let images = Array.from(pet.images[0]); //needed to access the first array first
for (let i = 0; i < images.length; i++) {
formData.append("images", images[i]);
}
} else {
formData.append(key, pet[key]);
}
});https://stackoverflow.com/questions/70088172
复制相似问题