Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Attachment size custom field JIRA

Deleted user Nov 17, 2016

Hi everyone

We have a considerable amount of large files in our JIRA instance. From 100mb to 1gb.

I wanted to do a query for issues with attachments larger than 100mb, so we can make sure we have the file on our local archive, before deleting it.

We have ScriptRunner installed, so I tried modifying this script to return attachmentSize instead of numbers of attachments, but I can't get it to work.

import com.atlassian.jira.component.ComponentAccessor

def attachmentManager = ComponentAccessor.getAttachmentManager()
def numberAttachments = attachmentManager.getAttachments(issue).size()

// use the following instead for number of PDFs
//def numberAttachments = attachmentManager.getAttachments(issue).findAll {a ->
// a.filename.toLowerCase().endsWith(".pdf")
//}.size()

return numberAttachments ? numberAttachments as Double : null

Does anyone have a suggestion as to how I modify this script? Or another way to get a list of issues with large attachments? (We are running JIRA 6.4)

Thanks for your help,

/Nikolaj

 

 

5 answers

1 accepted

1 vote
Answer accepted

Hi,

If you want to display in an issue the  size of attachments attached to it, you can use this in a scripted custom field.

import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.Issue
import java.util.*
def sizeAll = {Collection<Attachment> attachments -> 
    def size = 0
    for (Attachment attachment : attachments) {
    	size += attachment.getFilesize()    
    }
    return size;
}
def totalSize = sizeAll(issue.getAttachments());
for (Issue subtask : issue.getSubTaskObjects()) {
    totalSize += sizeAll(subtask.getAttachments())
}
totalSize

Note: this sums up the attachments of the subtasks as well. Without the subtasks, the script is simpler:

import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.Issue
import java.util.*
def sizeAll = {Collection<Attachment> attachments -> 
    def size = 0
    for (Attachment attachment : attachments) {
    	size += attachment.getFilesize()    
    }
    return size;
}
def totalSize = sizeAll(issue.getAttachments());
totalSize

 

Tibor

Deleted user Nov 18, 2016

This works! Perfect smile

Thank you very much. I don't know what I would do without this forum.

What you're suggesting is to search directly on the server or?

Yes I was, but OK I understand now. Tibor's script is fine, although I would prob just write it as :

issue.attachments*.filesize.sum()

Make sure you set a Number searcher so you can find issues with a large total attachment size.

Your script is somewhat simpler smile

Deleted user Nov 18, 2016

Hi Jamie


Thank you very much for your help!

What context are you trying to use that script in? It appears to be a workflow function...?

Can you not just do this with unix find and use the attachment store on disk?

0 votes
Deleted user Nov 17, 2016

Hi Jamie

I was using it as a Scripted Custom Field, which is a part of the ScriptRunner addon. The script works and the custom field is updated with the amount of attachments. This led me to believe that it would be possible to modify it to return attachment size in a custom field.

Our JIRA instance is hosted at another company and I'm not an advanced user, so my ideas are limited to quite basic use of JIRA.

What you're suggesting is to search directly on the server or?

Hi @JamieA I know this is very old thread but would like to check one thing.

issue.attachments*.filesize.sum()
size += attachment.getFilesize()   

 Both above line is telling us the total number of files attached to issue but how If I would like to know the actual size of the attached file in MB/GB. 

@Omprakash Thamsetty 

just add this, thanks to Adaptavist team for the query. 

import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.core.util.FileSize
import com.atlassian.jira.issue.Issue
import java.util.*
    
def sizeAll = {Collection<Attachment> attachments ->
    def size = 0
    for (Attachment attachment : attachments) {
     size += attachment.getFilesize()    
    }
    return size;
}
def totalSize = sizeAll(issue.getAttachments());
for (Issue subtask : issue.getSubTaskObjects()) {
    totalSize += sizeAll(subtask.getAttachments())
}

FileSize.format(totalSize)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

328 views 9 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you