Skip to content

HttpClient request, report progress not working in production #32429

@GProDev

Description

@GProDev

Affected Package

The issue is in the http client (@angular/common/http) request report progress feature

Description

In my Angular app, I uploads files to a Node.js web service.

So I am using the HttpClient request method with reportProgress option on.
When I run the app in dev mode (ng build), reportProgress works fine, but when run ng build --prod reportProgress stops working.

Here is a sample from the angular service that uploads files

const formData: FormData = new FormData();
formData.append('file', file, file.name);
const req = new HttpRequest('POST', url, formData, { reportProgress: true });
const progress = new Subject<number>();
const sub = this.http.request<any>(req).subscribe(
        event => {
          if (event.type === HttpEventType.UploadProgress) {
            const percentDone = Math.round(100 * event.loaded / event.total);
            progress.next(percentDone);
          } else if (event instanceof HttpResponse) {
            progress.complete();
            const datafiles = event.body.map(item => new Datafile(item));
            callback(datafiles);
          }
        },
        err => errCallback(err)
      );

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions