【问题标题】:angular ng2-file-upload get blob of file uploadedangular ng2-file-upload 获取上传的文件块
【发布时间】:2020-01-15 05:59:19
【问题描述】:

我正在使用 ng2-file-upload 来上传任何类型的图像和文件,常规示例工作正常,但我实际上想检索上传文件的 blob 而不是使用常规处理,因为我'我要在服务器端做我自己的处理。 谁能告诉我选择后如何上传文件的blob?

我想做的是这样的:

this.uploader.onAfterAddingFile = fileItem => {
  fileItem.withCredentials = false;
  this.file
  .uploadAttachment(fileItem)
  .pipe()
  .subscribe(data => {
    console.log(data);
  });
};

【问题讨论】:

  • 从这个answer,我猜blob可以像这样创建:const blob = new Blob([this.file], { type: 'application/pdf' });

标签: angular ng2-file-upload


【解决方案1】:

就我而言,我已经解决了从 FileItem 检索 File 对象的问题。

let file = fileItem.file;
const blob = new Blob([file.rawFile], { type: file.type });
 this.file
  .uploadAttachment(blob)
  .pipe()
  .subscribe(data => {
    console.log(data);
 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 2020-01-07
    • 1970-01-01
    • 2019-11-25
    • 2018-07-30
    相关资源
    最近更新 更多