How to download a base64-encoded image?

  1. If you want to download it using JavaScript (without any back-end) use:

    window.location.href="https://stackoverflow.com/questions/14011021/data:application/octet-stream;base64," + img;
    

    where img is your base64 encoded image.

  2. If you want to allow the user to specify a file name, use the download attribute of the a tag:

    <a download="FILENAME.EXT" href="data:image/png;base64,asdasd...">Download</a>
    
    • Notice: The download attribute is not supported by very old browsers

Leave a Comment