Converting binary image file (Blob) to base64 string on PlayBook?
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?
- 06-25-2013, 12:19 AM #2
If it's working for text it should be working for images...
Have you tried writing it to canvas or something to see if that works?Need an app for your blog/business or want some BB10 coding help? PM me for rates
OSBB - For Devs, by Devs. : OSBB Forum on CrackBerry : Create OTAs with Dropbox : Unlock your Escreen : BB10 Escreen Unlock App : Hybriding Basics : Custom PB Browser Homepage : BB10 on PlayBook (depreciated) : BB Github Contributors : SKBR : Restoring after Downgrading : BB10 Leak Checking App (leakCheck)My Apps in BlackBerry App World - Proceeds pay for diapers
Take a picture and upload it using Webworks on Playbook | Network Programming in .NET, 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.
- By PTZ in forum BlackBerry PlayBookReplies: 4Last Post: 10-19-2011, 09:32 PM
- By mtint in forum BlackBerry PlayBookReplies: 15Last Post: 08-28-2011, 02:09 AM
- By oshyy in forum BlackBerry PlayBookReplies: 0Last Post: 06-22-2011, 09:29 AM
- By housej55 in forum Developers LoungeReplies: 0Last Post: 11-10-2010, 10:12 AM
- By DHeal in forum BlackBerry Curve 83xxReplies: 1Last Post: 12-23-2008, 08:16 PM