Recently I got a requirement to download base64 string as .pfx file in Angular application.
So I did that using Blob API in javascript.
So I did a sample application on stackblitz using Angular.
const data = 'some text'; const blob =new Blob([data],{type:'application/octet-stream'}); this.fileUrl =this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob));
As above we need to create Blob object. As second parameter we need to specify Mime type. And in Angular to make the Blob url safe in DOM we can use DomSanitizer.
We have to import DomSanitizer
import { DomSanitizer } from '@angular/platform-browser';</div> // constructor constructor(private sanitizer: DomSanitizer) { }
In html template
<a>DownloadFile</a>
🙂
What if I want to access JSON object from server and display in angular 7 with a download pdf link.
LikeLike
Hello Ashish. I did not quite understand the your requirements. Could you please elaborate more?
LikeLike
Nice, but is not working in IE
LikeLike
Hi Chu, I haven’t tested in IE. IE always give issues 😊.
LikeLike