How to get a binary data size in mobile (javascript)?
Inside a javascript block
var binary_string = window.atob($parameters.BinaryData);$parameters.Size = binary_string.length;
Hi Filipe,
You can use BinaryDataSize. You need to Manage Dependencies:
I hope it helps.
Regards
Paulo Cação wrote:
MOBILE
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.
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:
Hum ok. Share with us :)
You can too save the binary size in other attribute, when save the binary.
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.
hello, is this solution with Uint8Array still viable? I just tried it out and it always returns 0 bytes.
This first solution is working for me but as you said, it returns a bigger size.var binary_string = window.atob($parameters.BinaryData);$parameters.Size = binary_string.length;
Do you know something? Thank you!