# Stop large attachments from syncing (Jira cloud - Jira server)

**URL:** <https://community.exalate.com/t/stop-large-attachments-from-syncing-jira-cloud-jira-server/5247>\
**Category:** General Questions\
**Tags:** exalate, usecase, cloud-jira, jira, migrated\_question, moved\
**Created:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/stop-large-attachments-from-syncing-jira-cloud-jira-server/5247 "2024-11-04T07:53:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/stop-large-attachments-from-syncing-jira-cloud-jira-server/5247/1 "2024-11-04T07:53:12Z")

</div>

_Originally asked by Syed Majid Hassan on 30 June 2022 [(original question)](https://oldcommunity.exalate.com/questions/58491719)_

* * *

We recently received the following requirement from a client who was syncing between Jira Server and Jira Cloud:

- Any large attachments should not be synced over to the destination
- But for every large attachment added to the source, a comment should be added to the destination side informing them that a large attachment was recently added on source.

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/stop-large-attachments-from-syncing-jira-cloud-jira-server/5247/2 "2024-11-04T07:53:13Z")

</div>

_Answer by Syed Majid Hassan on 30 June 2022_

The challenge here is not to stop the attachments from syncing over. We can easily do that by doing the following on the outgoing side:

```auto
replica.attachments = issue.attachments.findAll {it.filesize <= 50000}

```

_This line would not add any attachments to the replica which are greater than 50,000 bytes._

The challenge, however, comes when you want to add a comment to the destination side informing the users that a large attachment has been added. Here is an approach to solve this:

- If a large attachment is added on source side, set a customKey to 1. Now read the value of that customKey on the destination side and if it is one, we can add a custom comment. But how do we stop duplication of this i.e. every time a sync is triggered, the customKey would be set and duplicate custom comments would be added on destination side.

So, it is clear that we somehow need to maintain the attachments data on source side and pass it on the destination side to avoid this duplication:

- On the source side, add a customKey to track the attachments which are being filtered out:

```auto
def bigAndSmallEnough = issue.attachments.inject(["big":[], "smallEnough":[]]) { r, a ->
  if (a.filesize <= 10) { r."smallEnough" += a }
  else { r."big" += a }
  r
}
replica.attachments = bigAndSmallEnough."smallEnough"
replica.customKeys."bigAttachments" = bigAndSmallEnough."big"

```

- On the destination side, check if the “bigAttachments” has changed since the previous sync. This is the key to saving you from duplicate comments. You can easily do this by using:

```auto
if (replica.customKeys."bigAttachments" != previous.customKeys."bigAttachments")

```

- Now within this if block, you are free to [add any comments](https://docs.idalko.com/exalate/display/ED/addComment) and format them as per requirement. What we have done here is to run over the “new” values in bigAttachments and printed out the filenames of those new files:

```auto
if (replica.customKeys."bigAttachments" != previous.customKeys."bigAttachments"){
    for (int i = previous.customKeys."bigAttachments".size(); i < replica.customKeys.'bigAttachments'.size();i++){
        issue.comments = commentHelper.addComment("WARNING: New Large File Added #${i+1}. ${replica.customKeys.'bigAttachments'[i].filename}", issue.comments)
    }
}

```

Here is a [video demonstration](https://oldcommunity.exalate.com/download/attachments/58491719/Large%20attachments%20-%20add%20comment%20on%20dest.mp4?version=1&modificationDate=1656593351329&api=v2)_(old community)_ of the aforementioned solution here.

Thanks & Happy Syncing

Majid

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/stop-large-attachments-from-syncing-jira-cloud-jira-server/5247/3 "2024-11-04T07:53:14Z")

</div>

_Answer by Chana on 03 July 2022_

Hi Majid,

Thanks for that, very useful!

Is it possible to add a link to the destination within the comment?

Thanks,

Chana

* * *

#### Comments:

> **Syed Majid Hassan commented on 14 July 2022**
>
> > Hi Chana,
> 
> Yes that would be possible by refining the script to the following:
> 
> ```auto
> if (replica.customKeys."bigAttachments" != previous.customKeys."bigAttachments"){
> for (int i=previous.customKeys."bigAttachments".size(); i/secure/attachment/${replica.customKeys.'bigAttachments'[i].id}/${replica.customKeys.'bigAttachments'[i].filename}", issue.comments)
>            
> }
> }
> 
> ```
> 
> Please let me know if you have any further questions on this one.
> 
> Thanks
> 
> Majid

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 6, 2024, 7:53am UTC](https://community.exalate.com/t/stop-large-attachments-from-syncing-jira-cloud-jira-server/5247/4 "2024-11-06T07:53:23Z")

</div>

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