06-24-2013 12:49 PM
I need to upload image files from the PlayBook to a webserver.
When using BB10, it's pretty easy, basically just using reader.readAsBinaryString(file) to get the file as a string, encode it into Base64, then send it with xml.send(fileData). That works fine with my Z10.
But the PlayBook seems to have it's own file handling system which doesn't work the same as BB10. I can read the image file just fine with blackberry.io.file.readFile(path, pbOpenImageFile), but that just gives me the binary Blob. How do I get that Blob converted to a Base64 string for sending with xml.send(fileData)?
blackberry.utils.blobToString(blobData) doesn't seem to work, at least not with my image data (works fine with my text files though). It also apparently has a size limit which could be a problem with images anyway.
Is there any way to get that Blob converted to a Base64 string?
Solved! Go to Solution.
06-24-2013 02:18 PM
06-24-2013 05:05 PM - edited 06-24-2013 05:05 PM
If I'm reading that code correctly, I think it only *decodes* data ("at the moment just decodes a binary base64 encoded").
I've found similar code examples though, and none seem to do the same magic that reader.readAsBinaryString(imagefile); on the BB10 does. The string returned from that works fine for uploading (after encoding to Base64). But the PlayBook doesn't have reader.readAsBinaryString(file);... so I guess I'm looking for it's equivilent, if there is one?
06-24-2013 05:24 PM
Oh... I've used this library before and I could have sworn it had both (but perhaps I just used the decoding part).
So Sorry!!! Anyway, here's another batch of code someone wrote that apparently does both decoding AND encoding
06-25-2013 01:43 PM
Taking the idea from here something like:
var can = document.getElementById('canvas');
var ctx = can.getContext('2d');
var img = document.getElementById('tweetpic');
ctx.drawImage(img, 0, 0);
var b64Text = can.toDataURL();
b64Text = b64Text.replace('data:image/png;base64,','')
var fileData = b64Text;
And then xml.send(fileData); as usual