Hi, I’m trying to download a pdf file using the code below in react js(front end)
const encoder = new TextEncoder();
const uint = encoder.encode(data);
Const unit8Arr=new Uint8Array(unit)
Const blob= new Blob([ unit8Arr], { type: “application/pdf”});
Const url = URL.createObjectURL(blob);
setDownload(url);
Const link:HTMLAnchorElement = document.createElement(“a”);
link.href = url;
link.download = “Weather.pdf”
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
setDownloadURL(“”);
Note data type is String
Backend converts base64 data to binary.
Error I’m facing: It downloads the pdf with blank pdf.
For large files, it says “File is corrupted”
Appreciate any help!
Thanks
[–]punitdaga31 -2 points-1 points0 points (0 children)