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.