首页 > 解决方案 > Angular中的渐进式上传文件

问题描述

angular.io站点中有一个上传文件的上传服务,但它不是完整的类 是否有一个丰富的类示例​​,用于上传具有最佳功能和模式的数据,包含渐进式错误处理和设置标题等...?建议的角度类包含以下代码:

  private getEventMessage(event: HttpEvent<any>, 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}.`;
    }
  }

标签: angulartypescriptfile-upload

解决方案



推荐阅读