Reputation: 733
My webpage displays an image from a base64 string.
Even if I put a wrong media type, the image is still rendered correctly (I use Firefox). For example:
src="data:incorrect;base64, ...base 64 string..."
Is there any reason for that ?
Moreover, I cannot know in advance the format of the image to display (as they are uploaded by the user), so, should I use simply image
as a media-type ?
Upvotes: 0
Views: 1537
Reputation: 724
Modern Browsers may display some common image types such as jpeg, png etc without proper mime type. but images in the form of SVG and all will not identify by the browser with out proper mime type. so it is better to use proper mime type even if it is working for you without proper mime.
Upvotes: 2
Reputation: 165
the format is :
data:{mimeType};base64,{code}
the mimeType maybe is:
data:text/html
data:text/javascript,Javascript
data:image/png;base64
data:image/jpeg;base64
only {code} is used for image.
in fact, if you use
<img src=a.jpg>
can diaplay, even if you change ext as a.asp
<img src=a.asp>
the image still can show.
some virus can use this method, but I think when base64 string, the ";"'s data is not used ,you can just split ";" it and only get the {code}
Upvotes: -1