Hi, I am building an app with Ionic an Angular. I have an endpoint which returns a pdf file attached in the http response. I want to open that pdf in the native browser.
I have written this code, in the browser the file is downloaded, but in Android it does not do anything
public downloadCertificate(courseId: number): void {
this.courseService.downloadCertificate(courseId).subscribe(
(response) => {
const blob = new Blob([response], { type: 'application/pdf' });
// Create a link pointing to the ObjectURL containing the blob.
const data = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = data;
link.download = 'certificate.pdf';
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
setTimeout(function () {
window.URL.revokeObjectURL(data);
link.remove();
}, 100);
}
);
}
I also tried to use this Capacitor Plugin. Do you know what is wrong in my code ?