Delete a pull request attachment in Bitbucket Data Center

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

This knowledge base article outlines the steps for removing a pull request attachment uploaded via the Bitbucket user interface.

Solution

Delete pull request attachment via API

  1. Find the internal ID for the attachment using this query against the Bitbucket database:

    select p.project_key AS project_key, r.slug as repo_slug, a.id as attachment_id, a.filename as attachment_filename from bb_attachment a inner join repository r on r.id = a.repository_id inner join project p on p.id = r.project_id where p.project_key='<PROJECT_KEY>' and r.slug='<REPO_SLUG>' and a.filename='<ATTACHMENT_FILENAME>';

    Replace the <PROJECT_KEY>, <REPO_SLUG> and <ATTACHMENT_FILENAME> placeholders.

  2. Delete the attachment using the Delete attachment API. Pass the attachment ID retrieved from the first step. Note that the API requires at least REPO_ADMIN permissions. Sample call using curl:

    curl -k -u <USER> -X DELETE '<BITBUCKET_BASE_URL>/rest/api/1.0/projects/<PROJECT_KEY>/repos/<REPO_SLUG>/attachments/<ATTACHMENT_ID>'

    Replace the <PROJECT_KEY>, <REPO_SLUG> and <ATTACHMENT_FILENAME> placeholders.

  3. Confirm that the attachment has been deleted by calling the Get an attachment API. The API requires at least REPO_READ permissions: Sample call using curl:

    curl -k -u <USER> '<BITBUCKET_BASE_URL>/rest/api/1.0/projects/<PROJECT_KEY>/repos/<REPO_SLUG>/attachments/<ATTACHMENT_ID>'

    The expected response is a 404 with the following exception that indicates the attachment has been removed successfully:

    { "errors": [ { "context": null, "message": "Attachment '1' does not exist.", "exceptionName": "com.atlassian.bitbucket.NoSuchObjectException" } ] }
  4. The image may still be cached on client browsers. Clear the browser's cache, try a different browser, or switch to incognito mode to verify that the image can no longer be loaded.

  5. Delete the pull request comment referencing the deleted attachment from the UI.

Updated on June 10, 2025

Still need help?

The Atlassian Community is here for you.