Get the name of a binary image with base64 when you download it


Suppose I have the following base64 image:

<img alt="imagen de prueba" width="16" height="16" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAA……… />

When I run the view in the browser and show the image, at the time of downloading, when I put save image as ... in name, it appears with the name of "descarga.png". I would like to know how to put the real name or one you want to the file to download.

asked by Danilo 13.01.2016 в 04:30

2 answers


The format of data URIs does not allow you to specify a name for the file but you have other alternatives.

You could add a download link, put the name in the attribute download and the data again in the attribute href

<a download="Nombre de prueba.png" href="data:image/png;base64,iVBOwSUgAB...">Descargar</a>
answered by 13.01.2016 / 05:15

One option is to use the download button if it works for you, leaving it like this:

 <a href="/images/nombredelaimagen.png" download="nombredelaimagen">Nombre de la imagen </a> 

I clarify that this button does not work in Safari browsers.

answered by 13.01.2016 в 20:32