java - Generate base64 string of an image to use in data URI -


how generate base64 string of image use in data uri?

i have base64 image encoding issue hope can with. i'm trying use data uri in web page (ie <img src="data:image/png;base64,ivborw..."/> org.apache.commons.codec.binary.base64 v1.8 generating base64 string of png image.

to generate base64 string have used:

base64.encodebase64urlsafestring(imagefile) 

the problem browser cannot render image. compared generated string 1 works , noticed differences apache base64 version has "_" , "-" characters instead of "/" , "+". internet see there different base64 formats assume apache's implementation not compatible browsers.

so wondering there library implements base64 format appropriate purposes? current fix replace characters rather use library.

according javadoc of base64.encodebase64urlsafestring method, seems design. check out link provided, says in javadoc:

encodes binary data using url-safe variation of base64 algorithm not chunk output. the url-safe variation emits - , _ instead of + , / characters. note: no padding added.

so want make sure use url-unsafe variation. that's method called encodebase64. use method instead:

base64.encodebase64(imagefile) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -