How to not send attachments larger than 10 MB

Originally asked by Francis Martens (Exalate) on 18 June 2021 (original question)


We got this situation.
We have a ADO to Jira integration

Jira allows the storage of only 10MB files. The setting can be adapted by the Jira team wants to limit the size to 10 MB.

Question - How can we limit the attachments to only attachments lower than 10 MB.


Answer by Michiel Meurs on 21 June 2021

Hi Francis Martens (Exalate) ,

Excellent question. This can be done fairly easily. The attachment has a property called “filesize” which is expressed in bytes. So in the script, we can add some logic that will filter out all attachments that have the filesize value that is greater than 10.000.000 bytes. (1MB = 1.000.000 bytes). Here it is:

def remoteAttachments = attachmentHelper.mergeAttachments(issue, replica)

//The max size of the attachments in bytes. 1MB = 1.000.000 bytes
def maxFileSize = 10000000
def refacturedList = []
for(file in remoteAttachments){
    if(file.filesize <= maxFileSize){
        refacturedList.add(file)
    }
}
issue.attachments = refacturedList

In the script, you’ll see that I created a new list, and in this list, I’ll be adding all attachments that are larger than or equal to 10MB.

Best regards,

Michiel


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.