【问题标题】:reportProgress in angular returns the total uploaded file and not the progress角度的 reportProgress 返回上传的文件总数而不是进度
【发布时间】:2018-08-04 14:09:21
【问题描述】:

在我的组件中我有这个

this.authService.addPost(post).subscribe(data => {
        if (data.type === HttpEventType.UploadProgress) {

        console.log(data);
        } else if (data.type === HttpEventType.Response) {
          if (data.body.success) {
            alert('post added');
            this.modalRef.close('Save click');
          } else {
            alert('an error has occured');
          }
        }

      });

这是我的服务

addPost(post) {

    const headers = new HttpHeaders({
      // add authorisation
      'Authorization': `Bearer ${this.authToken}`
    });

    return this.httpClient.post<Addpost>('' + this.domain + 'add/addPost', post,
      {
        reportProgress: true,
        observe: 'events',
        headers: headers,
      });
  }

所以我的问题出在控制台中,我得到的是上传文件的总状态,而不是进度。我得到了这样的东西

{type: 1, loaded: 21076, total: 21076}

我尝试了很多参数,但都无济于事

【问题讨论】:

标签: angular http observable angular6 angular-httpclient


【解决方案1】:

在这种情况下最后返回完整的 http 请求。您需要从 data => data.body 更改目标响应。

利润

【讨论】:

  • 与其用文字写如何修改代码,不如把修改后的代码贴出来……
猜你喜欢
  • 1970-01-01
  • 2021-07-13
  • 2020-08-25
  • 2017-01-13
  • 1970-01-01
  • 2018-06-04
  • 1970-01-01
  • 1970-01-01
  • 2020-02-26
相关资源
最近更新 更多