Welcome to the CrackBerry Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 3 of 3
  1. kmsoft's Avatar
    CrackBerry Abuser

    Posts
    145 Posts
    Global Posts
    146 Global 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?
    Willow - Twitter client for BB10 and PlayBook
    SiteBook - Manage your bookmarks, tasks and notes on BB10 and PlayBook (PlayBook version free!)
  2. SCrid2000's Avatar

    Posts
    10,526 Posts
    Global Posts
    10,538 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
    145 Posts
    Global Posts
    146 Global 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.
    Willow - Twitter client for BB10 and PlayBook
    SiteBook - Manage your bookmarks, tasks and notes on BB10 and PlayBook (PlayBook version free!)

Similar Threads

  1. how to turn flash on playbook
    By PTZ in forum BlackBerry PlayBook
    Replies: 4
    Last Post: 10-19-2011, 09:32 PM
  2. Replies: 15
    Last Post: 08-28-2011, 02: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, 09:29 AM
  4. App files request to manual install on BB
    By housej55 in forum Developers Lounge
    Replies: 0
    Last Post: 11-10-2010, 10:12 AM
  5. Photo transfer (image files are to large)
    By DHeal in forum BlackBerry Curve 83xx
    Replies: 1
    Last Post: 12-23-2008, 08:16 PM

Posting Permissions