Sometimes, we want to force download of image from src="data:image/jpeg;base64…" with HTML.
In this article, we’ll look at how to force download of image from src="data:image/jpeg;base64…" with HTML.
How to force download of image from src="data:image/jpeg;base64…" with HTML?
To force download of image from src="data:image/jpeg;base64…" with HTML, we set the download attribute on the anchor element.
For instance, we write
<a download="YourFileName.jpeg" href="data:image/jpeg;base64,iVBO...CYII=">
<img src="data:image/jpeg;base64,iVBO...CYII=" />
</a>
to set the download attribute to the name of the downloaded file.
We set href to the base64 URL of the image to download it as an image when we click on it.
Conclusion
To force download of image from src="data:image/jpeg;base64…" with HTML, we set the download attribute on the anchor element.