[英]How to receive multiple images in Web Api from Angular 4 application
I am new to Angular 4 and Web API ,Here I am trying to upload multiple images from Angular 4 application to Web API . 我是Angular 4和Web API的新手,在这里我试图将多个图像从Angular 4应用程序上传到Web API。
In this case I have successfully received images in API ,While I debugging the API I could see the count of the uploaded Images. 在这种情况下,我已经成功通过API接收了图片,同时调试API时,我可以看到上传图片的数量。
But When I trying to save the image in folder only one images is stored .And in database all the image path is showing the same path . 但是当我尝试将图像保存在文件夹中时,仅存储一个图像。在数据库中,所有图像路径都显示相同的路径。
When I debugging the API in the foreach loop all the images showing the same Image Name . 当我在foreach循环中调试API时,所有显示相同图像名称的图像。
service.ts[Angular 4] service.ts [角度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)
}
can anyone help me to solve this . 谁能帮我解决这个问题。
I found that I have did the mistake in service file . 我发现我在服务文件中做错了。
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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.