I have base64 encoded image. If I put it right into html it works:
<img src="data:image/png;base64,..."/>
But when I put all that base64 content into a separated file, it doesn't:
<img src="image.base64.txt"/>
I tried changing extension to .png, but it doesn't help. Any ideas?
Images encoded with Base64 can be embedded in HTML by using the <img> tag. This can help to increase the page load time for smaller images by saving the browser from making additional HTTP requests.
The <img> tag has a src attribute and contains the Data URL of the image. A Data URL is composed of two parts, which are separated by a comma. The first part specifies a Base64 encoded image, and the second part specifies the Base64 encoded string of the image. Add also an alt attribute.
Instead, they are stored in their raw binary form in a binary column, blob column, or file. Base64 is only used as a transport mechanism, not for storage. For example, you can embed a base64 encoded image into an XML document or an email message. Base64 is also stream friendly.
You would need to send the correct Content-type, Content-encoding and charset HTTP headers along with the file. Note that they are all part of the data: URI schema as well. You really should have a charset=utf-8
or similar clause between the content-type and the encoding:
url(data:image/png;charset=utf-8;base64,...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With