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
-
Show total size of all attachments on a record
I wrote this blog some time ago as a simple test of the size of attachments as that are attached. If it does not refresh properly as you are changing records, there is not much the current structure can do about that.
-
Show total size of all attachments on a record
Thanks, @WarrenBelz. Should I take your response to mean there are no solutions to the two issues I'm experiencing?
-
Show total size of all attachments on a record
Hi @WarrenBelz. After updating and testing with your new code, I noticed all prior tested items in the sharepoint list reflect the same attachment size of the most recent submission. I also see when I go back in to the sharepoint list items, after closing the browser, the attachment size is blank.
Is there a setting I missed so that each record retains the correct size of their respective attachments and the size persists when going back into the items at a later time?
-
-
Show total size of all attachments on a record
That's great news! Can you please confirm the link to the latest post?
-
Show total size of all attachments on a record
Yours is not the latest version - it is missing the new
ClearCollect( colSize, {ImSize: 0} );
at the top. You can also run this when you want to clear the value.
I just ran a test here with the code on OnAddFile, OnRemoveFile and OnUndoRemoveFile and it worked as expected (although it took a few seconds to resolve).
-
Show total size of all attachments on a record
Don't mean to bother you, but I have a really important case I need this solution for... 🙂
Here is the link to a 15 sec video showing the behavior. Your script (I think it's the latest version) runs on the OnFileAdded property of the attachment box.
-
Show total size of all attachments on a record
Try now - I must admit I had not had a chance to test that
-
Show total size of all attachments on a record
Yes, I did start with a ForAll statement. used the script from the original post though. Will check out the new one.
Thank you @WarrenBelz !
*This post is locked for comments