jeudi 4 mars 2021

window.open(url) fails to download the pdf file in android webview

I have the following code on the client side. This one calls server-side API (Server-side code is in node js)

window.open(url);

and following code on the server-side.

        res.setHeader('Content-disposition', 'attachment;filename=query.pdf');
        res.setHeader('Content-Type', 'application/pdf;name=query.pdf');
        const buff = Buffer.from(resp.body.objectList[0].fileInByte, 'base64');
        res.send(buff);

Here, we are calling the backend API to get the response (resp) and then using fileInByte (this is a pdf file) from that response which is baase64 encoded string to create a Buffer (Uint8Array) and returning it as a response. When we run client-side code on the browser, pdf is getting downloaded successfully. When we open the client in android webview, and try downloading pdf, it is failing to download the pdf.

This is the error that is coming on the android app

enter image description here

Can someone please help here in fixing download issue in android?




Aucun commentaire:

Enregistrer un commentaire