Breadcrumbs

Total attachment size in MB

πŸ“š

This template displays the sum of the size of the attachments in the current work item in MB.

Configuration

To use the Total attachment size in MB template, simply select it from the template grid. Filter by Attachments to find it faster.

Parameters

This template does not require any additional parameter configuration.

Expert mode

If you switch to Expert mode you can see the formula field in the Expression Parser. You can now tweak the expression to create a custom formula field based on this template.

Expression

Jira expression:

issue.attachments.reduce((result, att) =>
            result + att.size, 0) / 1024 / 1024

Display as

Number

Formatting style

Custom format

Pattern

0.## MB

Details

1. What does the expression do?

This expression calculates the total size of all attachments on the current work item and converts the result into megabytes (MB).


2. Step-by-step breakdown

Let's break it down:

  • issue.attachments: This refers to the list of all attachments on the current work item.

  • .reduce((result, att) => result + att.size, 0): This part goes through each attachment (att) and adds up their sizes (att.size). The reduce function starts with 0 and keeps adding each attachment's size to get the total size in bytes.

  • / 1024 / 1024: This converts the total size from bytes to megabytes. There are 1024 bytes in a kilobyte and 1024 kilobytes in a megabyte, so dividing by 1024 twice gives you the size in MB.


3. Examples

Suppose a work item has three attachments with the following sizes:

  • Attachment 1: 1,048,576 bytes (1 MB)

  • Attachment 2: 2,097,152 bytes (2 MB)

  • Attachment 3: 524,288 bytes (0.5 MB)

The expression would work as follows:

  • Add up the sizes: 1,048,576 + 2,097,152 + 524,288 = 3,670,016 bytes

  • Convert to MB: 3,670,016 / 1024 / 1024 = 3.5 MB


4. Real-life use cases

  • You want to monitor the total size of files attached to a work item to ensure it doesn't exceed storage limits.

  • You need to report or display the total attachment size for auditing or compliance purposes.

  • You want to create a custom field in Jira that shows users how much space their attachments are using in a more readable format (MB instead of bytes).