Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Is there a way to manipulate a Blob as binary data

I need to upload a file to DropBox and I have to build my own multipart (not to use the send({media: myMedia}) ). It works fine with a text file, but I can't add an image. To do so I would have to base64encode the image binary representation of the image. The read method of File returns a Titanium.Blob : it would be nice to get the binary data (as an array ?).
Has anybody already solved this kind of problem ?

— asked July 20th 2010 by Benoit Lelong
  • blob
  • file
  • image
  • iphone
  • xhr
1 Comment
  • Any progress on this ? Because i still do not know how to upload an image to dropbox!

    — commented May 14th 2012 by Prathiba N

7 Answers

  • I converted the string format input to binary by using this javascript function. If you have any other functions please provide that here

    function toBin(str)
    {
        var i,j,d;
        var arr = [];
        var len = str.length;
        for (i = 1; i<=len; i++)
        {
            //reverse so its like a stack
            d = str.charCodeAt(len-i);
            for (j = 0; j < 8; j++) 
            {
                arr.push(d%2);
                d = Math.floor(d/2);
            }
        }
        //reverse all bits again.
        return arr.reverse().join("");
    }
    var binary = toBin("Harsh");
    alert(binary);
    
    — answered May 22nd 2012 by Harsh Punnoose
    permalink
    0 Comments
  • any ideas how to do it??

    — answered November 7th 2012 by Adrian Z
    permalink
    0 Comments
  • To convert Blob object to base64 string use this method

    var base64stringOfImage = Titanium.Utils.base64encode(blob object).
    

    it works and i have used it for such conversion. let me know if it works for you people.

    — answered November 9th 2012 by Ashish Nigam
    permalink
    1 Comment
    • hi ashish Titanium.Utils.base64encode(blob object) works fine in ios if i pass image blob but it force closes when i try to pass a 10MB sqlite file as blob to it. I belive that its happening because of memory constraint in mobile devices..Is there a way to upload an sqlite file to server?

      — commented December 13th 2014 by Maninder Bhatti
  • me too

    — answered December 17th 2011 by Javier Rubio
    permalink
    0 Comments
  • Me too.

    — answered February 16th 2012 by Owen Borseth
    permalink
    0 Comments
  • +1

    — answered February 25th 2012 by Marzpet Vardanyan
    permalink
    0 Comments
  • i wanna know too

    — answered December 20th 2010 by Alex Hensen
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.