在 HttpEventType.UploadProgress 之后无法获得 HttpEventType.Response

Unable to get HttpEventType.Response after HttpEventType.UploadProgress

之后我可以在服务器上上传视频,我想从 api 获得响应并推送到数组中。

但是上传视频后无法得到响应

Component.ts


    const fd = new FormData();
    fd.append('file', this.selectedFile);
    this.request = this.createTraining.uploadVideo(fd,{reportProgress: true,
      observe:'events'}).subscribe((event :HttpEvent<any>) =>{

        if(event.type == HttpEventType.UploadProgress){
          this.loaderService.hide();
          this.state = 'in';
          this.name = this.selectedFile.name;
          this.progress= Math.round (event.loaded / event.total*100) ;
          if(this.progress == 100){
            this.show = false;
            this.progress = 0;
            this.state = 'out';
            this.trainingItemList.push({name:this.name,order:null, type:this.selectedFile.type,path:null,question:null});
          }
        }
         **if(event.type == HttpEventType.Response) {
          console.log(event.body.message);**
        }
      },
      error=>{
        console.log(error);
      });
  }

服务

uploadVideo(video,progress):Observable<any>{
    return this.http.post<any>('http://localhost:8080/employee/upload',video,progress);
  }

我想在上传视频后得到回复,但无法进入

if(event.type == HttpEventType.Response) {
          console.log(event.body.message);

Api Response after upload which i want to get

message property is part of the HttpErrorResponse class. To access the response body of the type HttpResponse, try to access only the body 属性.

替换

console.log(event.body.message);

console.log(event.body);