0

In my jsp page, I have a manipulated photo within a html5 canvas and I want to upload it to facebook upon clicking the upload button.

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

out.println("Published photo ID: " + publishPhotoResponse.getId());

I am using Restfb for the uploading part in my servlet. However, I have no clue what attribute is needed for me to pass over to servlet side for processing (for example: "xxx"). When I used toDataURL, the URL of the image is base64. Does facebook api allows me to upload photo using the base64 format?

var base64URL = document.getElementById('canvasImg').src;
var decodedURL = escape(window.atob(base64URL));
alert(decodedURL);

The above coding seems to contain error as it won't display the alert. Should I decode the base64 data first before handling it over to servlet or should I pass the whole base64 data to servlet to handle the decoding?

Sky
  • 163
  • 2
  • 4
  • 15
  • _“Does facebook api allows me to upload photo using the base64 format?”_ – Nope. But simply de-coding it should be no problem, right? – CBroe Oct 07 '13 at 11:37
  • encode the b64 string before posting to facebook. see: http://stackoverflow.com/questions/2820249/base64-encoding-and-decoding-in-client-side-javascript – geevee Oct 07 '13 at 11:50
  • Sorry, I got a bit of confusion here, should I decode or encode the base64 data? So after I done it, it will produce the actual URL of the image from html5 canvas for me to use as argument ("xxx.jpeg")? – Sky Oct 07 '13 at 12:03
  • I have tried to decode it (updated in my post) but I got error. Anything that I did wrong? – Sky Oct 07 '13 at 13:22
  • Of course you won’t get “the actual URL of the image” – because it _has none_. And what you are trying to decode here is not base64 encoded data, but a _Data URI_ – the base64 encoded image data is _part_ of that, but it consists of some more info, that you have to remove first. – CBroe Oct 07 '13 at 15:11
  • Should I decode the Data URI in script before passing over to servlet or should I pass to servlet to handle the decoding? Which way is more effective? – Sky Oct 07 '13 at 17:32
  • And also how should I convert the decode data into an input stream? – Sky Oct 07 '13 at 18:56

0 Answers0