How to use URI of image data as an InputStream?

I extracted base64 ur64 data from html5 canvas. In my servlet, I would like to decode the uri of the data and use it as an input stream, as shown in "xxx" below. The following coding is to post the image in html5 canvas in my facebook account. I am using restfb.

FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class,
BinaryAttachment.with("test.jpeg", getClass().getResourceAsStream("xxx")),
Parameter.with("message", "Test"));

How can i achieve this? Thanks.

Updated Closer, but still not working!

In my jsp:

var d = document.getElementById('img').src;
window.location.href = "upload?src=" + d;

In my servlet:

String d = req.getParameter("src");
String head = "data:image/jpeg;base64,";
String base64 = d.substring(head.length()-1);

byte[] buf = DatatypeConverter.parseBase64Binary(base64);
ByteArrayInputStream is = new ByteArrayInputStream(buf);

FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class,
BinaryAttachment.with("test.jpeg", is),
Parameter.with("message", "Test"));

Are there any errors in my coding as it seems to get into the error somewhere inside the servlet. I cannot view the errors because it is running on the server.

+4
1

! , , . Image 64 String, - String Image.

javax.xml.bind.DatatypeConverter.parseBase64Binary(String), byte[] String.

byte[] ByteArrayInputStream.

+2

All Articles