I have an angular page where I display a PDF inside an iframe with:
<iframe id="documentFrame" width="100%" height="600" [src]="documentData" *ngIf="documentData"></iframe>
My pdf is a blob fetched from an API with:
getDocument(id: number): Observable<Blob> {
return this.http.get<any>(environment.apiUrl + '/api/documents/' + id, { responseType: 'blob' as 'json', observe: 'response' }).pipe(
map((result: HttpResponse<Blob>) => {
return result.body;
}));
}
And to fill my iframe with my blob, I make:
this.dataService.getDocument(doc.id)
.subscribe(res => {
this.documentUrl = URL.createObjectURL(res);
this.documentData = this.sanitizer.bypassSecurityTrustResourceUrl(this.documentUrl);
});
It's working well for display. But as you can see below, the generated url is not pretty and if I click on save, the default filename is the random name:
Is there a way to specificy a filename with this solution? It seems that a blob have only a size and a binary content, and I didn't see any way to parametize the generated URL.. Thanks for your help !