我正在从发布请求中获取文件上传进度。直到我添加
{ reportProgress: true, observe: 'events' }
-一切都很好。
添加上述配置后,我根本无法获得响应正文。有时响应也会被取消。
请在此处建议正确的方法。我正在使用Angular 8:
这是我的代码:
Attachment(attachmentData) {
const formData = new FormData();
formData.append('File', attachmentData.File);
formData.append('CreatedBy', String(attachmentData.CreatedBy));
formData.append('PageDetailId', String(attachmentData.PageDetailId));
return this.http.post<any>(environment.url+ `Attachment`, formData, { reportProgress: true })
.pipe(
map(response => {
console.log('hi')
if (response.type === HttpEventType.UploadProgress) {
const mes = Math.round(100 * response.loaded / response.total);
console.log('ms', mes); //not getting
}
else if (response.type === HttpEventType.Response) {
const body = response.body.toString();
console.log('ms', body); //not getting?!
}
}),
catchError(this.handleError)
);
}