I have some problems with Blob. I have a website running on Vue 3, and there is one action that is downloading pdf from the backend, but it's not working from mobile browser. It's actually working from the mobile browser, but we have another browser that is opening (just like when you click on facebook url it's opening in their own browser). So every time when I try to download it from that browser it fails. What am I doing wrong?
async function downloadPdfLink(args: IPaymentDownloadPDFArguments): Promise<void> {
isPDFLoading.value = true;
return get('/users/' + args.userId + '/payments/' + args.paymentId + '/download-pdf', {
responseType: 'arraybuffer'
}).then((response) => {
const blob = new Blob(
[response.data],
{ type: 'application/pdf' }
)
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
const name = convertToKebabCase(args.name) + moment(new Date()).format("_YYYY_DD_MM");
link.href = url;
link.setAttribute('download', name + '.pdf');
document.body.appendChild(link);
link.click();
})
.catch((reason) => {
throw new Error(reason)
})
.finally(() => {
isPDFLoading.value = false;
})
}
btw I'm not really able to debug it from that browser.