Home > Net >  Argument of type 'Object' is not assignable to parameter of type 'Blob | MediaSource&
Argument of type 'Object' is not assignable to parameter of type 'Blob | MediaSource&

Time:06-16

The blob in URL.createObjectURL(blob) gives the error:Argument of type 'Object' is not assignable to parameter of type 'Blob | MediaSource'. Any solution to fixing this?

async downloadPDF(): Promise<void> {
 try{
   this.http.post(environment.pdf_url, { responseType: 'blob'}).subscribe(
     (blob) => {
       const a = document.createElement('a')
       const objectUrl = URL.createObjectURL(blob)
       a.href = objectUrl
       a.download = `xxxxx.pdf`;
       a.click();
       URL.revokeObjectURL(objectUrl);
     }
   )
 } catch (err) {
   console.log(err)
   }

}

CodePudding user response:

You are doing a post method and you are missing your body parameter, you are going straight to the options param with your code. Change it to this:

this.http.post(environment.pdf_url, {}, { responseType: 'blob'})

  • Related