cancel
Showing results for 
Search instead for 
Did you mean: 
WarrenBelz

Show total size of all attachments on a record

I posted a blog a little while back on how to show the size of an attachment or uploaded file to the user. What if you want to see the total size of all attachments ? 
Firstly, insert a gallery (you can hide it after the settings below are made and I will call galAttach in the code below) with the Items

YourAttachmentControlName.Attachments

Now put an Image control in the Gallery (called imAttach below) with the Image

ThisItem.Value

You will need to trigger the next piece, so a button with “Size” or similar below the attachment control will do the job. If you want to make it dynamic instead, put this code at the point you display the Form (maybe Screen OnVisible) and also on the Attachment control OnAddFile, OnRemoveFile and OnUndoRemoveFile.

ClearCollect(
   colSize,
   {ImSize: 0}
);
ForAll(
   galAttach.AllItems,
   Collect(
      colSize,
      {
         ImSize: 
         (Len(
            JSON(
               imAttach.Image,
               JSONFormat.IncludeBinaryData
            )
         ) - 814) / 137000
      }
   )
);
UpdateContext(
   {
      varSize: 
      Sum(
         colSize,
         ImSize
      )
   }
)

A collection is being made here containing a calculation of the size of the JSON text conversion of each image, then a Variable is being set to the total of all of these values, so you can then have a Label with

Total Attachment size: & " varSize & " Mb"

 

Comments