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 ?
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);
-
any ideas how to do it??
-
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.
-
me too
-
Me too.
-
+1
-
i wanna know too