How to use the @angular/common/http.HttpEventType.UploadProgress function in @angular/common

To help you get started, we’ve selected a few @angular/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lishewen / ngx-spa-wechat4work / src / app / ext / uploader.service.ts View on Github external
private getEventMessage(event: HttpEvent, file: File) {
    switch (event.type) {
      case HttpEventType.Sent:
        return `Uploading file "${file.name}" of size ${file.size}.`;

      case HttpEventType.UploadProgress:
        // Compute and show the % done:
        const percentDone = Math.round(100 * event.loaded / event.total);
        return `File "${file.name}" is ${percentDone}% uploaded.`;

      case HttpEventType.Response:
        this.result = event.body as server.weUIUploadFileResult[];
        return `File "${file.name}" was completely uploaded!`;

      default:
        return `File "${file.name}" surprising upload event: ${event.type}.`;
    }
  }
github angular / angular / aio / content / examples / http / src / app / uploader / uploader.service.ts View on Github external
private getEventMessage(event: HttpEvent, file: File) {
    switch (event.type) {
      case HttpEventType.Sent:
        return `Uploading file "${file.name}" of size ${file.size}.`;

      case HttpEventType.UploadProgress:
        // Compute and show the % done:
        const percentDone = Math.round(100 * event.loaded / event.total);
        return `File "${file.name}" is ${percentDone}% uploaded.`;

      case HttpEventType.Response:
        return `File "${file.name}" was completely uploaded!`;

      default:
        return `File "${file.name}" surprising upload event: ${event.type}.`;
    }
  }
  // #enddocregion getEventMessage
github vugar005 / ngx-awesome-uploader / src / app / demo-file-picker / demo-file-picker.adapter.ts View on Github external
map( (res: HttpEvent) => {
        if (res.type === HttpEventType.Response) {
          return res.body.id.toString();
        } else if (res.type ===  HttpEventType.UploadProgress) {
            // Compute and show the % done:
            const UploadProgress = +Math.round((100 * res.loaded) / res.total);
            return UploadProgress;
        }
      })
      );
github xmlking / ngx-starter-kit / libs / core / src / lib / services / profile.service.ts View on Github external
private getStatusMessage(event) {
    let status;

    switch (event.type) {
      case HttpEventType.Sent:
        return `Uploading Files`;

      case HttpEventType.UploadProgress:
        status = Math.round((100 * event.loaded) / event.total);
        this.uploadProgress.next(status);
        return `Files are ${status}% uploaded`;

      case HttpEventType.DownloadProgress:
        status = Math.round((100 * event.loaded) / event.total);
        this.downloadProgress.next(status); // NOTE: The Content-Length header must be set on the server to calculate this
        return `Files are ${status}% downloaded`;

      case HttpEventType.Response:
        return (event as HttpResponse).body; // `Done`;

      default:
        return `Something went wrong`;
    }
  }
github runbox / runbox7 / src / app / compose / compose.component.ts View on Github external
)).subscribe((event) => {
            if (event.type === HttpEventType.UploadProgress) {
                const progress = event.loaded * 100 / event.total;
                this.uploadprogress = progress === 100 ? null : progress;
            } else if (event.type === HttpEventType.Response) {
                if (!this.model.attachments) {
                    this.model.attachments = [];
                }
                (event.body as any).result.attachments
                    .forEach((att: any) => {
                        att.file = att.filename;
                        this.model.attachments.push(att);
                    });

                this.uploadprogress = null;
                this.uploadingFiles = null;
                this.submit();
            }
github nishantmc / angular-material-fileupload / src / lib / matFileUpload / matFileUpload.component.ts View on Github external
}).subscribe((event: any) => {
        if (event.type === HttpEventType.UploadProgress) {
          this.progressPercentage = Math.floor( event.loaded * 100 / event.total );
          this.loaded = event.loaded;
          this.total = event.total;
        }
        this.onUpload.emit({ file: this._file, event: event });
      }, (error: any) => {
        if (this.fileUploadSubscription) {
github infor-design / enterprise-ng / src / app / fileupload-advanced / fileupload-advanced.demo.ts View on Github external
this.http.request(req).subscribe(event => {
      if (event.type === HttpEventType.UploadProgress) {
        const percentDone = Math.round(100 * event.loaded / event.total);
        status.setProgress(percentDone);
      } else if (event instanceof HttpResponse) {
        status.setCompleted();
      }
    },
    (err: HttpErrorResponse) => {
github opensds / opensds-dashboard / src / app / business / monitor / config / config.component.ts View on Github external
this.monitor.uploadConfigFile(conf_file, configType).subscribe(event => {
      if (event.type === HttpEventType.UploadProgress){
        this.showProgress = true;
        this.progress = Math.round(100 * event.loaded / event.total);
      }
      else if (event.type === HttpEventType.Response){
        this.msgs = [];
        this.msgs.push({severity: 'success', summary: 'Success', detail: 'Configuration Uploaded! The service will be restarted shortly.'});
      }  
    },
    err=>{
github asadsahi / AspNetCoreSpa / src / Presentation / Web / ClientApp / src / app / shared / components / forms / forms.service.ts View on Github external
return tap((event: HttpEvent) => {
      if (event.type === HttpEventType.UploadProgress) {
        cb(Math.round((100 * event.loaded) / event.total));
      }
    });
  }
github Squidex / squidex / src / Squidex / app / shared / services / assets.service.ts View on Github external
filter(event =>
                event.type === HttpEventType.UploadProgress ||
                event.type === HttpEventType.Response),
            map(event => {