HTML <img> tag and src attribute as a byte[]
Hi everybody
I have a question is it possible to send a byte[] to the src attribute in a <img> HTML tag. What i would like to gain is a way of reading an img file from the jar in a custom tag which is no problem. Problems start when i want to send a byte[] which I have read from the InputStream to the StringBuffer which contains the HTML code.
byte[] dataByte =null;
String charEncoding ="UTF-8";
InputStream in = imageURL.openStream();//InputStream to the img file inside a jar
StringBuffer buffer =new StringBuffer();
StringBuffer sb =new StringBuffer();
String imgData ="";
int data;
while((data = in.read()) != -1)
{
buffer.append(new Integer(data).toString(), charEncoding);
}
imgData = buffer.toString();
dataByte = imgData.getBytes();
The problem starts in this line, i think i need some encoding to do this.
sb.append("<img src=\""+dataByte.toString()+"\">");
thx in advance
[1421 byte] By [
alien_01a] at [2007-11-27 10:44:26]

I know that u can do something like that :
<html>
<body>
</body>
<IMG
SRC="data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7"
ALT="Larry">
</html>
I want to do exactly the same thing but via custom tags. The problem is as u say i have some data in the src attribute but the web browser doesn't interpret it right. sory for the long html source.
IE doesn't support data: URI's.
What do you mean custom tags? Is this HTML to a browser or XML that you are going to parse? If the latter, you should still encode the bytes as base64 or some similar encoding, otherwise you don't know what's in the data that could muck with the XML parsing. In which case, typically, I'd define it as CDATA in a tag... <data>[the encoded data]</data>