Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-36015

REST API Needs ability to remove specific versions of an attachment

    • 8
    • 6
    • We collect Confluence feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

      NOTE: This suggestion is for Confluence Server. Using Confluence Cloud? See the corresponding suggestion.

      If someone has uploaded a file with the same name as an existing file, it becomes the most recent version. If this last upload needs to be removed, the only way to do it and preserve previous versions is to download all versions of the file, remove the attachement (which deletes all revisions), then re-upload all versions carefully typing in the comments.

      It would be very helpful if a specific revision of an attachment could be removed.

          Form Name

            [CONFSERVER-36015] REST API Needs ability to remove specific versions of an attachment

            A fix for this issue is available in Confluence Data Center 9.0.1.
            Upgrade now or check out the Release Notes to see what other issues are resolved.

            James Whitehead added a comment - A fix for this issue is available in Confluence Data Center 9.0.1. Upgrade now or check out the Release Notes to see what other issues are resolved.

            Atlassian Update – 28 March 2023

            Hi everyone,

            We're excited to share that you'll soon be able to use a REST API to remove specific versions of an attachment. While we'd marked this as landing in Confluence 8.9, it requires a bit more attention and we now plan to deliver it in Confluence 9.0 instead. Please look out for it in the Confluence Release Notes, and continue to watch this ticket for further updates.

            Kind regards,

            Jacqueline Bietz

            Confluence Data Center

            Jacqueline Bietz added a comment - Atlassian Update – 28 March 2023 Hi everyone, We're excited to share that you'll soon be able to use a REST API to remove specific versions of an attachment. While we'd marked this as landing in Confluence 8.9, it requires a bit more attention and we now plan to deliver it in Confluence 9.0 instead. Please look out for it in the Confluence Release Notes, and continue to watch this ticket for further updates. Kind regards, Jacqueline Bietz Confluence Data Center

            Adam Labus added a comment -

            Hi guys,

            as a workaround please check Extender for Confluence app and documentation Delete specific versions of an attachment 

            Cheers

            Adam

            Adam Labus added a comment - Hi guys, as a workaround please check  Extender for Confluence app and documentation Delete specific versions of an attachment   Cheers Adam

            I also think this is urgently needed. I know that Atlassian has built in similar things with Confluence 7.16 - but only for DataCenter!

            As beside not everybody having the possibility to immediately go to DC or Cloud (because having several thousand licensed users on server will not have management jumping out of joy for financial reasons when you come with such migration wishes), this REST based delete option for attachments is a must if you want to reduce your data storage size BEFORE any cloud move!

            I tried the work around using the DELETE method on 

            /rest/experimental/content/{id}/version/{versionId}

            but also this might not be the way to go, as it seems to remove only the version from the database but NOT from the filesystem - compared to manual deletion which does exactly that.

            Having attachments with versions > 1000 (remember companion app?) manual deletion of old version cannot be the way to go.

            Martin Podhovnik added a comment - I also think this is urgently needed. I know that Atlassian has built in similar things with Confluence 7.16 - but only for DataCenter! As beside not everybody having the possibility to immediately go to DC or Cloud (because having several thousand licensed users on server will not have management jumping out of joy for financial reasons when you come with such migration wishes), this REST based delete option for attachments is a must if you want to reduce your data storage size BEFORE any cloud move! I tried the work around using the DELETE method on  / rest /experimental/content/{id}/version/{versionId} but also this might not be the way to go, as it seems to remove only the version from the database but NOT from the filesystem - compared to manual deletion which does exactly that. Having attachments with versions > 1000 (remember companion app?) manual deletion of old version cannot be the way to go.

            Team, Please let us know is there any way to remove attachments from trash, as all said above its pain and space consuming part on the server where it is not needed.

            Deepthi Akula added a comment - Team, Please let us know is there any way to remove attachments from trash, as all said above its pain and space consuming part on the server where it is not needed.

            Is there an API for removing all attachments on a given page? It is a pain to remove the attachment one by one. That slows down the process. When the page is updated, we need to update the attachment as well. That results in one PUT call + calls as many as the number of attachments. So basically, to update a page you end up making multiple calls. Is there a way to delete all attachment at once? I can do a multipart POST call to upload all a

            antony terrence added a comment - Is there an API for removing all attachments on a given page? It is a pain to remove the attachment one by one. That slows down the process. When the page is updated, we need to update the attachment as well. That results in one PUT call + calls as many as the number of attachments. So basically, to update a page you end up making multiple calls. Is there a way to delete all attachment at once? I can do a multipart POST call to upload all a

            Paul Mata added a comment - - edited

            @Jeff Grant, I was able to cobble together a working bash script that allows me to update my existing attachments on a specific page. I don't know if there are better ways to do this, but it works for me. I realize this is not Python, but maybe my script can help you figure out what you need to do.

            bash script to update Confluence attachments
            # Set initial variables for connection and other items in the script
            USER_NAME=tempuser
            USER_PASSWORD=password
            CONFLUENCE_BASE_URL='https://<your.site.url>/confluence' # update this to match your site config
            PAGE_ID=31424562 #page with the attachments
            base_dir="../BuildInfoFiles" # this is where I have my files, if you have them in the same dir as this script, you won't need this variable
            date=$(date +%m/%d/%Y)
            time=$(date +%T) 
            
            # Populate this array with the attachment id in the same order as they are in your directory
            # I have actually put these in a different order and it still seems to work
             
            arrayid_list=(
             31424615
             31424591
             31424579
             31424576
             ) 
            
            id_index=0 # create the index variable so that we can increment later 
            
            # Iterate through the text files in the current directory to upload each file to the target page
            # Again, if you are not using a separate folder to hold your files for upload, adjust (i.e. "for i in *.txt; do" to get all text files in the current directory)
            
            for i in ${base_dir}/*.txt; do 
            
            file_id=${id_list[$id_index]} # create the variable for the correct attachment id that will be used in the curl command 
            
            curl -D- -u $USER_NAME:$USER_PASSWORD -X POST -H 'X-Atlassian-Token: nocheck' -F 'file=@'$i -F 'comment=Uploaded on '${date}' at '${time} -F 'minorUpdate=true' ${CONFLUENCE_BASE_URL}/rest/api/content/${PAGE_ID}/child/attachment/${file_id}/data >/dev/null
            
            (( id_index ++ )) # increment the index
            
            done
            

            Like I said, there may be simpler ways to do this, but it does what I need it to do for a specific page that I have attachments that are pushed from our build server to keep our build info updated. Hope it helps.

             

            Paul Mata added a comment - - edited @Jeff Grant, I was able to cobble together a working bash script that allows me to update my existing attachments on a specific page. I don't know if there are better ways to do this, but it works for me. I realize this is not Python, but maybe my script can help you figure out what you need to do. bash script to update Confluence attachments # Set initial variables for connection and other items in the script USER_NAME=tempuser USER_PASSWORD=password CONFLUENCE_BASE_URL= 'https: //<your.site.url>/confluence' # update this to match your site config PAGE_ID=31424562 #page with the attachments base_dir= "../BuildInfoFiles" # this is where I have my files, if you have them in the same dir as this script, you won't need this variable date=$(date +%m/%d/%Y) time=$(date +%T) # Populate this array with the attachment id in the same order as they are in your directory # I have actually put these in a different order and it still seems to work arrayid_list=( 31424615 31424591 31424579 31424576 ) id_index=0 # create the index variable so that we can increment later # Iterate through the text files in the current directory to upload each file to the target page # Again, if you are not using a separate folder to hold your files for upload, adjust (i.e. " for i in *.txt; do " to get all text files in the current directory) for i in ${base_dir}/*.txt; do file_id=${id_list[$id_index]} # create the variable for the correct attachment id that will be used in the curl command curl -D- -u $USER_NAME:$USER_PASSWORD -X POST -H 'X-Atlassian-Token: nocheck' -F 'file=@' $i -F 'comment=Uploaded on ' ${date} ' at ' ${time} -F 'minorUpdate= true ' ${CONFLUENCE_BASE_URL}/ rest /api/content/${PAGE_ID}/child/attachment/${file_id}/data >/dev/ null (( id_index ++ )) # increment the index done Like I said, there may be simpler ways to do this, but it does what I need it to do for a specific page that I have attachments that are pushed from our build server to keep our build info updated. Hope it helps.  

            Tobias added a comment -

            Hello together, 

            we also need some information about this issue. 

            Tobias added a comment - Hello together,  we also need some information about this issue. 

            Jeff Grant added a comment -

            Solutions?  Is there python code for removing an existing attachment? Or updating (rather than uploading) an attachment?

            Issue:  We are successfully uploading confluence attachments, but when we try to do an overwrite, it errors and says attachment is already there.

            Jeff Grant added a comment - Solutions?  Is there python code for removing an existing attachment? Or updating (rather than uploading) an attachment? Issue:  We are successfully uploading confluence attachments, but when we try to do an overwrite, it errors and says attachment is already there.

            Rafael Corredor,

            My apologies. It should be both. Seems I missed one of the two.

               <entry>
                <string>com.atlassian.confluence.plugins.confluence-file-notifications:file-content-remove-notification</string>
                <boolean>false</boolean>
              </entry>
            
              <entry>
                <string>com.atlassian.confluence.plugins.confluence-file-notifications:file-content-remove-email-notification-template-body</string>
                <boolean>true</boolean>
              </entry>

            My prod is at 6.13.11, but am going to 7.4.3 next week. Works as expected in both and in all my envs. I missed it because I have a lot of behaviors disabled.

             

            Steve Hadfield added a comment - Rafael Corredor , My apologies. It should be both. Seems I missed one of the two. <entry> <string>com.atlassian.confluence.plugins.confluence-file-notifications:file-content-remove-notification</string> < boolean > false </ boolean > </entry> <entry> <string>com.atlassian.confluence.plugins.confluence-file-notifications:file-content-remove-email-notification-template-body</string> < boolean > true </ boolean > </entry> My prod is at 6.13.11, but am going to 7.4.3 next week. Works as expected in both and in all my envs. I missed it because I have a lot of behaviors disabled.  

              f9221957a5e4 Akshay Rai
              8a7280258d42 Eric Brown
              Votes:
              108 Vote for this issue
              Watchers:
              73 Start watching this issue

                Created:
                Updated:
                Resolved: