duplicated attachments in a space: writing code for scriptrunner for blocking or notification of
Asked by Steve Hastings:

Hi all,

I am trying to block or notify the occurrence of attachments with the same filename in a space. I have been in touch with the clever team at Adaptavist. Their Scriptrunner product has the capacity, using the Listener feature to raise these notifications. Our conversations with Tony at Adaptavist are below.

Is there anyone there who would be interested in creating the Listener script for Confluence Cloud (and Server) proposed by Tony? I'm happy to pay for your efforts or it would be script we could share with the community.

Please let me know! Thanks very much. Steve

*

  #### Tony Gough {#toc-hId-1458633368}

  7 hours ago

  Hi Steve,

  Unfortunately we are limited in our capacity to help customers with custom coding questions, as these by their very nature are limitless. Atlassian has a [community site](https://community.atlassian.com/), which is our preferred venue for custom code Q\&A. This also enables us to put information like this in a more public space, so that everyone benefits from the answer. We of course prioritize support covered by our SLA, but we do try to answer community questions when we can.

  That said, you should find the [Confluence Cloud REST API](https://developer.atlassian.com/cloud/confluence/rest/) helpful. You should be able to accomplish what you need making appropriate rest calls to [Get content](https://developer.atlassian.com/cloud/confluence/rest/#api-content-get) and [Get attachments](https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-child-attachment-get).

  I hope you find this information useful.

  Kind regards,  
  Tony

* Your request status changed to **Waiting for Customer**.7 hours ago
* ![Steve Hastings](https://www.gravatar.com/avatar/8dc15b2fc6762de7ddb0c099b99a07c6?d=mm&s=48)

  #### Steve Hastings {#toc-hId--1093523593}

  Yesterday 9:14 PM

  Hi Tony. Thank you very much for your help on this. I will further investigate an event listener. If I need help creating the script can you recommend a team who could do that?  
  Thanks, Steve
* Your request status changed to **With Support**.Yesterday 9:14 PM
* Your request status changed to **Waiting for Customer**.Yesterday 11:01 AM
* ![Tony Gough](https://productsupport.adaptavist.com/rest/servicedesk/1/servicedesk/customer/avatar/15809)

  #### Tony Gough {#toc-hId-649286742}

  Yesterday 11:01 AM

  Hi Steve,

  It sounds like what you want should be achievable using an [event listener](https://scriptrunner-docs.connect.adaptavist.com/confluencecloud/script-listeners.html) which fires on the Attachment Created event. This will give you access to the 'attachments' variable which contains a list of attachments which were uploaded, as well as the 'attachedTo' variable which represents the page.

  Further information is available on the Confluence Cloud API documentation, which is linked to from the ScriptRunner Script Listeners page.

  I hope this is helpful to you, please let us know if you have anything further.

  Kind regards,  
  Tony

* Your request status changed to **With Support**.Yesterday 10:50 AM
* ![Adaptavist Support](https://www.gravatar.com/avatar/a544b5a52292fe2255a8292d3d0441e6?d=mm&s=48)

  #### Adaptavist Support {#toc-hId--1902870219}

  Yesterday 3:15 AM

  Thanks for raising a request with Adaptavist Support. Please note our team is based in the UK and operate UK working hours, 9am to 5pm Monday to Friday. We try to respond to all new requests within 24 hours.

  If your request is about getting help with one of your scripts, please consider using the following resources:
  * [Adaptavist Script Library](https://library.adaptavist.com/)
  * [ScriptRunner Consultants](https://www.adaptavist.com/atlassian-consulting-services/) who can work directly with your key stakeholders to address specific business needs
  * [Training](https://www.adaptavist.com/atlassian-training/adaptavist-learn/) on Adaptavist apps for you and your team

  Thanks,  
  The Adaptavist Support team
*

  #### Details {#toc-hId--160059884}

  Yesterday 3:15 AM

  SEN
  :   279abfba-b315-3e72-90b9-3cea529a48d6

  ScriptRunner Licence
  :   Evaluation

  Licence Tier
  :   Server - 10 users - starter licence

  Atlassian Version
  :   Confluence

  Data Center?
  :   No

  Description

  :   **hi there, I am trying to block the occurrence of attachments with the same filename in a space. how can I use scriptrunner for confluence cloud to raise an alert when scriptrunner detects two attachments of the same filename within a confluence space?**   
      **thanks and kind rgds, Steve**

<https://productsupport.adaptavist.com/servicedesk/customer/portal/40/SRCLSUP-9>


Answers:
author: Davin Studer
body: I wrote a script like this for Jira that will compare attachments on ticket A to the attachment being uploaded on ticket B. If it matches any on ticket A the attachment will be deleted. Some of my code could probably be recycled into what you are trying to do. Alas, I do not have ScriptRunner for Confluence. Below are the Community articles I wrote about it.

[Remove Jira Issue Attachments by MD5 Hash](https://community.atlassian.com/t5/Jira-articles/Remove-Jira-Issue-Attachments-by-MD5-Hash/ba-p/735454)  
[Remove Jira Issue Attachments by MD5 Hash Redux](https://community.atlassian.com/t5/Jira-articles/Remove-Jira-Issue-Attachments-by-MD5-Hash-Redux/ba-p/737447)

comments: author: Davin Studer
body: As think about it from a design standpoint you would probably want to persistently store the hashes of all your attachments in the database so that you can compare quickly against the has of the attachment being uploaded. It would probably be a drain on the system to do a realtime scan to get the hashes of all the current attachments when the upload listener fires off.


author: Steve Hastings
body: Thank you Davin for your great input.Much appreciated! I'll let all know how I go. Kind Rgds, Steve


Tags: adaptavist

cloud

confluence-cloud

scriptrunner