Obtain the size of files uploaded

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business Rules examples > Documents and files > File management with expressions >

Obtain the size of files uploaded

In many situations it is desirable to know the size of the files uploaded in order to perform different actions. For instance, validate if the total size of the files uploaded is grater than an specific value.


To obtain the size of a file-type attribute you must create an expression. In it, obtain the list of all files uploaded and go through each record extracting the size of each one.


The following expression shows how the total size of the files stored in the RelatedDocuments file-type attribute (from the Business Opportunity entity) is obtained. The size obtained should not be greater than 5 MB (5.242.880 bytes). If the size exceeds this value, a message is displayed to the user through a validation message using the CHelper.ThrowValidationError function. This expression is executed when Next is clicked in the form of a task.


To obtain the size of a file inside a file-type attribute, use the .length property of the Data attribute.




//Obtain array of files

var UploadedFile = Me.getXPath("BusinessOpportunity.RelatedDocuments");

//Initialize a variable to sum the size of each value

var TotalSize = 0;

//Iterate every uploaded file

for(var i=0; i<UploadedFile.size(); i++) {

//Use the .length property of the file content (Data attribute)

 var Filesize = UploadedFile.get(i).getXPath("Data").length;

//Add the recently obtained file size

 TotalSize = TotalSize + Filesize;


//Show the validation if the file size exceed the defined value

if(TotalSize > 5242880) {

 var message = "The size of the uploaded files is greater than 5 MB. Current File Size: " + (TotalSize/1024)/1024 + " MB"




From the Work Portal in the form where the expression was configured, you can validate the total size of the uploaded files.