Results 1 to 4 of 4
  1. kmsoft's Avatar
    CrackBerry Abuser

    Posts
    118 Posts
    Thread AuthorThread Author   #1  

    Default 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?
    Creator of SiteBook (manage your bookmarks, tasks and notes) and Willow (twitter client) for BB10 and PlayBook
  2. SCrid2000's Avatar

    Posts
    10,372 Posts
    Global Posts
    10,384 Global Posts
    PIN
    PM me.
    #2  

    Default

    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?
  3. kmsoft's Avatar
    CrackBerry Abuser

    Posts
    118 Posts
    Thread AuthorThread Author   #3  

    Default

    Quote Originally Posted by SCrid2000 View Post
    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?
    Yup, thanks, that's what I ended up doing (which works). Taking the idea from 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.
    Creator of SiteBook (manage your bookmarks, tasks and notes) and Willow (twitter client) for BB10 and PlayBook
  4. arronlee's Avatar
    CrackBerry User

    Posts
    19 Posts
    Global Posts
    20 Global Posts
    #4  

    Default

    Hi, kmsoft.
    Are there any 3rd party
    Image Converting toolkits can help binary image file (Blob) to base64 string on PlayBook? I think using a toolkit can make all the conversion process much more convenient. Right?



    Best regards,
    Arron

Similar Threads

  1. how to turn flash on playbook
    By PTZ in forum BlackBerry PlayBook
    Replies: 4
    Last Post: 10-19-2011, 08:32 PM
  2. Replies: 15
    Last Post: 08-28-2011, 01:09 AM
  3. How do i play swf file with Active X content on playbook
    By oshyy in forum BlackBerry PlayBook
    Replies: 0
    Last Post: 06-22-2011, 08:29 AM
  4. App files request to manual install on BB
    By housej55 in forum Developers Lounge
    Replies: 0
    Last Post: 11-10-2010, 09:12 AM
  5. Photo transfer (image files are to large)
    By DHeal in forum BlackBerry Curve 83xx
    Replies: 1
    Last Post: 12-23-2008, 07:16 PM

Posting Permissions