Deleting more than one attachment at a time?

Jerry D. October 19, 2016

Is there a faster way to delete topic attachments? In our 5.0 version, you can only delete one attachment at a time !@#$%^&

3 answers

1 vote
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 27, 2016

There's some custom HTML you can add that will allow you to delete up to 20 attachments at a time. The code is in this JIRA ticket's comments, but I will also copy it to this page:

https://jira.atlassian.com/browse/CONF-17020

<script>
AJS.toInit(function() {
  if ( AJS.Meta.get('is-space-admin') || jQuery('#space-admin-link').length > 0 ) {
    if ( window.location.href.indexOf("viewpageattachments.action") >= 0 && jQuery(".removeAttachmentLink").length > 1 ) {
      jQuery('tr[id^="attachment-"]').each(function() {
        var attachmentId = jQuery(this).attr("id").substring(11);
        jQuery(this).find(".removeAttachmentLink").parent().after('<li><input type="checkbox" class="bulk-attachment-delete" name="' + this.getAttribute("data-attachment-filename") + '" value="' + attachmentId + '"></li>');
      });
      jQuery('table.attachments th.actions-column').css('text-align','right').css('width','220px');
      jQuery('th.actions-column').html('<input type="checkbox" onclick="if (this.checked) { jQuery(\'.bulk-attachment-delete\').attr(\'checked\',\'checked\') } else { jQuery(\'.bulk-attachment-delete\').removeAttr(\'checked\') }"> ');
      jQuery('#download-all-link').css('display','inline-block').after('<a href="#" title="Delete all selected attachments" style="display:inline-block;float:right;padding-right:20px;margin-top:10px;padding-left:20px;background:url(\'data:image/gif;base64,R0lGODlhEAAQAKIAAHBwcOTk5Hh4eP///4GBgZOTkwAAAAAAACH5BAAHAP8ALAAAAAAQABAAAAMpOLrcPiAC8RhV1wnJY8Yd91UkFEbPiToqkKrvGYdz9xAn8QRFVwQlUgIAOw==\') no-repeat left center;" onclick="removeAttachments(jQuery(\'.bulk-attachment-delete:checkbox:checked\'));return false;">Delete Selected Attachments</a>');
    }
  }
});
var removeAttachments = function(checkboxes) {
  var confluenceVersion = parseFloat(AJS.params.versionNumber.substring(0,3));
  var doRemoveAttachments = function(checkboxes) {
    if (checkboxes.length) {
      var currentCheckbox = checkboxes.pop();
      if ( confluenceVersion >= 5.5 ) {
        jQuery.ajax({
          type: 'DELETE',
          url: contextPath + '/rest/api/content/' + currentCheckbox.value,
          success: function(response) {
            doRemoveAttachments(checkboxes);
          }
        });
      } else {
        jQuery.ajax({dataType: 'json',
          contentType: 'application/json',
          type: 'POST',
          url: contextPath + '/rpc/json-rpc/confluenceservice-v2/removeAttachment',
          data: '[' + AJS.params.pageId + ',"' + currentCheckbox.name + '"]',
          success: function( response ) {
            if (response == true) {
              doRemoveAttachments(checkboxes);
            }
          }
        });
      }
    } else {
      location.reload();
    }
  }
  var dialog = new AJS.Dialog({
    width: 400,
    height: 170,
    id: "areyousure-dialog",
    closeOnOutsideClick: true
  });
  dialog.addHeader("Are you sure?");
  dialog.addPanel("Panel 1", "<p>You are about to delete " + checkboxes.length + " attachments. Continue?</p>", "panel-body");
  dialog.addButton("OK", function (dialog) {
    dialog.hide();
    if (checkboxes.length > 0) {
      doRemoveAttachments(jQuery.makeArray(checkboxes));
    }
  });
  dialog.addLink("Cancel", function (dialog) {
    dialog.hide();
  });
  dialog.show();
}
</script>
0 votes
EPS Software Engineering AG
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 19, 2016

Hi Jerry,

Thank's for the idea. We will add this feature to our Page Tree Eraser. In the mean time you could use our Page Tree Creator to copy the page tree without attachments, delete the original and move the copied back. Yes, for the moment it's a ugly work around.

Regards,
Stephan

0 votes
Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 19, 2016

Not that I know of. It is frustrating. If I have to delete a lot of attachments, I copy out the content on the page temporarily, and then delete the page, followed by creating a new page with the same content, reattaching the attachments I want. Not a great solution, but sometimes faster.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events