4

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

我想做的是这样的:

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

1 回答 1

0

就我而言,我已经解决了从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);
 });
于 2020-07-09T10:56:14.413 回答