我是角4和Web的新手,这里我尝试将多幅图像从角4应用程序上传到Web。
在本例中,我已经在API中成功地接收到了图像,而我在调试API时可以看到上传的图像的数量。
但是,当我试图将图像保存在文件夹中时,只有一个图像存储在数据库中,所有的图像路径都显示相同的路径。
当我在foreach循环中调试API时,显示的所有图像都是相同的图像名。
service.tsAngular 4
ImageInsert(mObject, mImage) {
const formData: FormData = new FormData();
formData.append('mFormData', JSON.stringify(mObject));
for (const file of mImage) {
formData.append('ImageFile', file, file.name);
}
return this.http.post(this.BASE_URL + `/api/ImageInsert`, formData)
}有人能帮我解决这个问题吗。
发布于 2018-12-04 16:36:52
我发现我在服务文件中犯了错误。
ImageInsert(mObject, mImage) {
const formData: FormData = new FormData();
formData.append('mFormData', JSON.stringify(mObject));
for (const file of mImage) {
formData.append('ImageFile'+file.name, file, file.name); //Need to have unique key name for each formData
}
return this.http.post(this.BASE_URL + `/api/ImageInsert`, formData)
}https://stackoverflow.com/questions/53617377
复制相似问题