961
Views
9
Comments
Solved
mobile binary data size
Question

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

2024-01-05 16-00-17
Filipe Lourenço
Solution

Inside a javascript block

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

2025-01-07 17-06-54
Paulo Cação
Champion

Hi Filipe,

You can use BinaryDataSize. You need to Manage Dependencies:


I hope it helps.

Regards

2024-01-05 16-00-17
Filipe Lourenço

Paulo Cação wrote:

Hi Filipe,

You can use BinaryDataSize. You need to Manage Dependencies:


I hope it helps.

Regards


MOBILE

2025-01-07 17-06-54
Paulo Cação
Champion

You can do this in mobile... Try it 

2019-10-27 01-32-56
Caio Santana Magalhães
 
MVP

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.


2024-01-05 16-00-17
Filipe Lourenço

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 

2025-01-07 17-06-54
Paulo Cação
Champion

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.


2024-01-05 16-00-17
Filipe Lourenço
Solution

Inside a javascript block

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

2019-10-27 01-32-56
Caio Santana Magalhães
 
MVP

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.

UserImage.jpg
José Camacho

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!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.