角度的reportProgress返回总上传文件而不是进度 [英] reportProgress in angular returns the total uploaded file and not the progress

查看:34
本文介绍了角度的reportProgress返回总上传文件而不是进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的组件中我有这个

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,
      });
  }

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

so my problem is in the console i get the total uploaded file status and not the progress. i get something like this

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

我试过很多参数都无济于事

i have tried so many parameters and all to no avail

推荐答案

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

In this case last return full http request. You need to change target responce from data => data.body.

利润

这篇关于角度的reportProgress返回总上传文件而不是进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆