Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
Posts: 58
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider

Re: PlayBook: readFile and blobToString for local binary files

Steps 4 - 6 were never been the problem. I was always able to download pdf files which were attached by my webOS devices. 

 

But I'm currently getting headaches for step 3. But in the meanwile I identified some special changes I made on my code for uploading the data to the webservice, because the webkit engine of the HP Touchpad is really old and I had to do some nasty tricks to get it going... Now I try to get back to the standard mechanism of chrome / webkit, for the PlayBook implementation.

 

I'm sure when I get going (IF I get it going anytime) I will have to smack my head against a wall or something like that... Sorry for bothering you so much.

 

Cheers,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com
Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: PlayBook: readFile and blobToString for local binary files

No problem - we're here to help. Give it a try with just real basic code on the PlayBook like I put in the sample a few messages ago. Once you've got that working you may need to have a small shim to handle both platforms but hopefully nothing too extreme.

Tim Windsor
Open Source Technical Lead
New Developer
Posts: 58
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider

Re: PlayBook: readFile and blobToString for local binary files

Thanks again, but I've got another issue related to this topic, and I again need your help. It's regarding the issues with the other encoding parameters. I already told you yesterday that now only encoding "binary" works. All other encodings delivering strange, shortened, strings. Please have a look at my posts from yesterday regarding the string length of the different encoding types. All tested with the pdf I send you. So you should be able to reproduce that easily by yourself.

 

I just found out that encoding the data to base64 before sending them to the webservice (I'm currently working heavily on a Springpad client for the BlackBerry PlayBook) was also a workaround to be able to upload the data from the webOS platform. This was the first answer by Springpad when I told them that I use base64 to encode the binary data:

 

Oh, yeah, don't do that. We literally just take the bytes and save them up to Amazon S3, so people downloading those files won't be seeing them properly.

 

After that they discovered that it's possible with base64, when I follow this limitations:

 

So the trick is both to do a query param of "encoding=base64" and prefix the post data with "data:base64,"

 

When I do this on the PlayBook I always got an internal server error (as soon as I add "data:base64," at the beginning of the base64 encoded string. I think the current webkit implementation did not like that prefix. Smiley Wink But when I did not add that prefix to the string and when I don't use the query parameter mention aboved by Springpad, then my file size of the uploaded pdf is to large at Springpad, because they really save the bytes. My pdf is then 733kb (?) instead of 5xx kb... And of course the file is damaged. So I need a way to just upload the binary data, I 1:1 transformation of the blob to a string with no encoding at all!

 

When I try blackberry.utils.blobToString(blobData); without encoding parameter the string length is 1468! That's way too short I think. Please have another look.

 

Thank you very much!

 

Cheers,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com
Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: PlayBook: readFile and blobToString for local binary files

I'm leaving for the long weekend in a few minutes and don't know if I'll have much opportunity to look at this until Tuesday - I'll see what I can do.

 

However, a couple things occur to me to try:

 

It's hard to say since I don't know their system, but "data:base64," looks like it might be wrong. It looks like they might be wanting a data URI, in which case the prefix should be "data:application/pdf;base64," so I'd say give that a try.

 

That approach is trying to get them to accept base64 and do what they need with it, but you can also try sending them the actual binary data. If you use blobToString(blob, 'binary') and then call atob(string), then send that value to their service. Careful to drop any temporary variables you get though, or you're going to run out of memory holding all these encodings around.

Tim Windsor
Open Source Technical Lead
New Developer
Posts: 58
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider

Re: PlayBook: readFile and blobToString for local binary files

Thanks a lot, Tim. I wish you a relaxing nice long weekend!

 

 

I will sure try what you mentioned. Hopefully one of it will solve this issue. I will document my results in any case!

 

Cheers,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com
New Developer
Posts: 58
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider

Re: PlayBook: readFile and blobToString for local binary files

I tried both of your suggestions without any luck. The first approach results in an internal server error and the second approach did not work either because of this error during the atob(string) call:

 

INVALID_CHARACTER_ERR: DOM Exception 5: An invalid or illegal character was specified, such as in an XML name.

 

I also tried it with btoa() instead of atob() and that did not throw an exception, but the string gets too large.

 

Anyway, I need a way to have a binary string, which is not base64 encoded! How could I achieve that?

 

And to repeat myself, because I think it's very important. Here are the string length for the available encoding types, all tested with blobToString for a PDF (size: 545.323 bytes!):

 

Converting with encoding "base64":

strData.length: 0 (did you broke something with your patch???)

 

Converting with encoding "binary": 

strData.length: 736.667

 

Without encoding parameter:

strData.length: 1468 

 

I had a look at the Utilities.as, that you updated. Because I have not done something with ActionScript before I tried to find some more informations on Google, to be able to convert a ByteArray to a String and I found different approaches.

 

I added my own encoding, called "svzi", to test the different kinds of transformation. I ended up with threee different ways to convert the ByteArray to a string, and I'm sure there will be much more.

 

This is what I added to blobToString():

 

else if (characterSet == "svzi")
{
   stringResult1 = ba.readUTFBytes(ba.length);
   stringResult2 = ba.readUTF();
   while (ba.bytesAvailable > 0) {
  stringResult3 += ba.readUTFBytes(1);
   }
}

 

stringResult1 and stringResult2 where both way too short, at around 1400 characters length. stringResult3 was really close to the result I expect (same amount as bytes in the blob). Something around 543.000 characters length.

 

I really wonder why this three approaches differ in the result that much? How could this be? And why am I not able to convert a 545.323 byte blog to a 545.323 long string????

 

Any help on this would be really much appreciated!

 

Cheers,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com
Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: PlayBook: readFile and blobToString for local binary files

You definitely won't get a base64 length string of the same length. That would be incorrect as well.

 

You should have approximately 33% more bytes in base64 than binary, as it converts 3 bytes to 4 base64 characters. 

 

One way to compare the results you are getting is with an online base64 converter. Just do a search and you'll find many that do this. For example, you could try copying the string from blobToString out of the console with WebInspector and paste it into a converter and download the binary file it gives you for testing. You can also compare the base64 string from the blobToString method and the result of converting the binary file on the website.

 

Is there any way you can send me a sample that actually sends data to the webserver so I can test more of the problem here? 

Tim Windsor
Open Source Technical Lead
New Developer
Posts: 58
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider

Re: PlayBook: readFile and blobToString for local binary files

Hi Tim!

 

I don't want to encode the string in base64, I just want a raw binary string. Smiley Happy

 

I will have a look tomorrow if I can send you an simple example, but I can't make any promises. 

 

But I would really appreciate an answer regarding my reported issues with the truncated strings when trying to encode the blod with something other than base64.

 

Cheers,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com
Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: PlayBook: readFile and blobToString for local binary files

The way that the interface works between AIR and Javascript works with Strings. Base64 is the standard way to encode binary data so that you can work with it in a web document.

 

Those other methods are not going to work because they do very different things. For blobToString, the encoding you provide is used to read the blob object. So it loads the binary object, but then uses the encoding to read it as some format of a string value. stringToBlob works similarly: the encoding you provide is used when writing the data, so it is encoded as a string. The underlying assumption of the API is that the objects you are working with are strings - which unfortunately is a problem for what you want to do and hence the patch.

 

The reason you are getting shorter results when trying with other encodings or with atob/btoa, is that the binary bytes that are being encoded include some sequence that messes up the encoder and cuts it short.

 

I feel like I've got a pretty good handle on what's happening on the device, but I don't know the interface of the server that you are working with, but with a sample I should be able to hack on it a bit and provide you with an answer.

Tim Windsor
Open Source Technical Lead
New Developer
Posts: 58
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider

Re: PlayBook: readFile and blobToString for local binary files

I will try to provide you a sample later today, which enables you to upload some binary data to springpad.

 

Cheers,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com