How to get a binary data size in mobile (javascript)?

Hi Filipe,

You can use BinaryDataSize. You need to Manage Dependencies:


I hope it helps.

Regards

Paulo Cação wrote:

Hi Filipe,

You can use BinaryDataSize. You need to Manage Dependencies:


I hope it helps.

Regards


MOBILE

You can do this in mobile... Try it 

Yes I know but I don't wanna go to the server.  Anyway I found out one solution and I will post as soon as I go to the office 

Filipe Lourenço wrote:

Yes I know but I don't wanna go to the server.  Anyway I found out one solution and I will post as soon as I go to the office 

Hum ok. Share with us :)

You can too save the binary size in other attribute, when save the binary.


Solution

Inside a javascript block

var binary_string =  window.atob($parameters.BinaryData);
$parameters.Size =  binary_string.length;

Solution

Paulo Cação wrote:

You can do this in mobile... Try it 

Sorry but that's a big no. Imagine you have a big blob of data of, say, 50MB. Then you'd have to stream it all to the server just to get its binary size.


Worst case scenario, the user goes offline or is under a limited data plan, then either: 1. your application breaks or 2. the user has to wait several minutes and might be charged for the transferred data just to get this trivial information.


The post marked as solution to this thread is pretty useful. Thanks Filipe.


Actually, just dug deeper and found out window.atob returns incorrect results.


Since it converts binary data to a base64 string, not only it's inefficient, it actually returns more bytes than the actual data size.


Here's a better solution using Uint8Array:


$parameters.Size = new Uint8Array($parameters.BinaryData).length;


Tested against a 144MB file and performed pretty good.