I receive an image in base64 from my nodejs express server like so:
fs.writeFileSync("image.png", tensor);
const readStream = fs.createReadStream('image.png');
readStream.pipe(res);
This is what I see in the console on the client.
Then I try to download it like this:
function downloadBase64File(contentType, base64Data, fileName) {
const linkSource = `data:${contentType};base64,${base64Data}`;
const downloadLink = document.createElement("a");
downloadLink.href = linkSource;
downloadLink.download = fileName;
downloadLink.click();
}
downloadBase64File("image/png", response.data, "image.png");
However, the downloaded image is corrupt, even though the size seems to be ok ~7.3MB:
What can be wrong here? How to send a base64 image to the client and download it?
Thank you