constructor(
private materialService: MaterialService,
) { }
/**
* 新增圖片
* @param name
* @param file
*/
createImg(name: string, files: File[]) {
this.materialService.createImg(name, files).subscribe();
}
/**
* 上傳圖片
* @param name
* @param files
*/
createImg(name: string, files: File[]) {
let formData = new FormData();
formData.set('name',name);
for (let i = 0; i < files.length; i++) {
formData.set(`file${i}`, files[i]);
}
return this.apiService.postEvent('/xxxyyy', formData);
}
https://ithelp.ithome.com.tw/articles/10208818
reportProgress:是否需要建立一個持續保持的通道
/**
* Post Api Event
* @param path
* @param body
* @param header
*/
postEvent(path: string, body: FormData, header: HttpHeaders = new HttpHeaders()): Observable<HttpEvent<Object>> {
return this.http.post(`https://abcdefg${path}`, body, { headers: header, observe: 'events', reportProgress: true });
}