使用. requests_Promise.all
我在这里做错了什么,因为我认为使用axios post方法会返回一个承诺?
const doUpload = async (fileList: FileList) => {
const requests: Array<void | AxiosResponse<any>> = [];
Array.from(fileList).forEach(async file => {
const formData = new FormData();
const blob = new Blob([file]);
formData.append(file.name, blob);
requests.push(
await axios
.post(
'https://jsonplaceholder.typicode.com/posts',
{
...formData,
},
{
headers: {
'Content-Type': 'multipart/form-data',
},
onUploadProgress: (progressEvent: ProgressEvent) =>
handleUploadProgress(progressEvent, file.lastModified),
}
)
.catch(error => {
handleUploadError(file.lastModified);
})
);
});
try {
const data = await Promise.all(requests);
console.dir(data);
} catch (error) {
console.log(error);
}
};
青春有我
largeQ
相关分类