4

I'm working with ng2-file-upload in order to upload images and files of any type, the regular example is working fine but i actually want to retrieve the blob of the file uploaded and not use the regular treatment since i'm going to do my own treatment in the server side. Can anyone please tell how to get the blob of the file uploaded after selecting it?

What i want to do is something like this :

this.uploader.onAfterAddingFile = fileItem => {
  fileItem.withCredentials = false;
  this.file
  .uploadAttachment(fileItem)
  .pipe()
  .subscribe(data => {
    console.log(data);
  });
};
bxxb
  • 740
  • 1
  • 9
  • 20
  • 1
    From this [answer](https://stackoverflow.com/a/35210392/2968762), I guess blob can be created like: `const blob = new Blob([this.file], { type: 'application/pdf' });` – Abhi Jan 23 '20 at 13:00

1 Answers1

0

In my case, I have solved retrieving the File object from FileItem.

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