Confiforms - Trying to get fileSize of all the attachments in a field

Sopaboba October 28, 2021

Hi experts

I need some help with an issue. I have a form with a field for picking files/attachments, type File/Attachment. Let's call this field myFiles

In this file, I can have 1,2,....., n files attached. I am triggering an IFTTT onModified that sends an Email with the files of that record. My problem is when the files are to heavy as to be sent by email. That's why I would like to know how to get the total size of all the files of one record, to trigger the email with the files in case they're less than 20MB in total and another different email without the files attached, including a link to a local resource in that case.

Is that possible? I think I should use a condition with something like:

myFiles.asAttachments.virtualfunctionhere:<SizeLimit (20MB) in this case

but I can't find the right one.

Could you help me with this? Thank you.

1 answer

1 accepted

0 votes
Answer accepted
Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 28, 2021

Hi

asAttachment transforms to Attachment object which you can query for properties

And fileSize is the one you are looking for (this answer is valid for server/dc and is different for cloud)

myFiles.asAttachment.fileSize

on cloud it is

myFiles.asAttachment.extensions.fileSize

as per structure provided by REST API - https://developer.atlassian.com/cloud/confluence/rest/api-group-content/#api-wiki-rest-api-content-id-get

Alex

Sopaboba October 28, 2021

Hi Alex

Thank you for such a quick response.

I have applied it this way

myFiles.asAttachments.extensions.fileSize

and the result is as follows:

242593 438073 588238

The result that I want to get is the addition of those three values.

What modification should I introduce in my sintaxis to get the total?

Thanks again.

Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 28, 2021

Well, that is because if you look more carefully then the function I use is "asAttachment"

Not "asAttachments" - which is rather different thing - https://wiki.vertuna.com/display/CONFIFORMS/Virtual+functions

Alex

Sopaboba October 28, 2021

Yes, I know the difference. If I use asAttachment, it returns only the size of the first file uploaded, replicating exactly as you told. Then I thought of applying it to asAttachments, and the result was as I wrote before.

What should I do then to get what I need? Perhaps adding to the sentence another virtual function to add up all the values?

Sorry to bother you and thank you for your time.

Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 28, 2021

If you know the difference then you should understand that what you do is not correct

To calculate the size of the all attachments associate with a field you may try to do something like

id.evaluateFormula([entry.myFiles.asAttachments.transform(extensions.fileSize).join(+)])

If you want to use an expression like that in filters then there is a trick to know...

id.evaluateFormula([entry._func.asEntryRef(entry.myFiles.asAttachments.transform(extensions.fileSize).join(+))]):>20971520

Alex

Sopaboba October 29, 2021

Thank you, Alex. That worked perfectly. I have applied the expression in a filter an works fine.

Of course my approach was not correct. That is precisely the reason why I ask here looking for your expertise.

Thank you for everything.

Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 29, 2021

You are very welcome. This is somewhat a "tribal knowledge" we need to document and explain better.

There is always a place for a better documentation - not doubt here

Alex 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events