如何通过http.post获得标题和正文响应?

时间:2019-02-13 13:12:11

标签: javascript

我在Angular 7中有带有进度栏的上传脚本,上传效果很好。现在我想处理来自php文件的响应(new_filename,... json格式)。我尝试了pipe (). map (),但很遗憾没有成功。

是否可以在订阅部分扩展php-response?

谢谢!

  onUpload() {
    const fd = new FormData();
    fd.append('file', this.selectedFile, this.selectedFile.name);
    this.http.post('http://xxxxx/upload.php', fd, {
      reportProgress: true,
      observe: 'events'
    }).subscribe( event => {
      if (event.type === HttpEventType.UploadProgress) {
        this.fileUpload.status = 'progress';
        this.fileUpload.message = Math.round(event.loaded / event.total * 100);
      } else if (event.type === HttpEventType.Response) {
        console.log('events', event);
      }
    });
  }

0 个答案:

没有答案
相关问题