I have a base64-encoded image from the server for which I want to force the download through JavaScript. Is is possible?
If you want to download it using JavaScript (without any back-end) use:
window.location.href = 'data:application/octet-stream;base64,' + img;
where img is your base64 encoded image.
img
If you want to allow the user to specify a file name, use the download attribute of the a tag:
download
a
<a download="FILENAME.EXT" href="data:image/png;base64,asdasd...">Download</a>
2.1m questions
2.1m answers
60 comments
57.0k users