Download all the attachments by space in Confluence Data Center
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles 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
Currently, a user or admin can download attachments from a page, or Download from the Attachment view, including downloading all attachments on a page.
Environment
Confluence Data Center
Known Issue
CONFSERVER-39428 - Download All Attachments from Space
Workaround
Confluence Data Center doesn't have a feature to download all attachments from a space.
However, you can download all attachments from a page.
Using Script and Confluence Rest API
The aim of the below Shell script is to download all the attachments placed in a specific space;
#!/bin/bash
# Define variables
BASE_URL=""
USERNAME=""
PASSWORD=""
SPACE_KEY=""
# Create a downloads folder if it doesn't exist
mkdir -p $SPACE_KEY/downloads
# Step 1: Get content IDs for type 'page' from Confluence API
echo "Fetching page IDs..."
page_ids=$(curl -s -u "$USERNAME:$PASSWORD" "$BASE_URL/rest/api/content?spaceKey=$SPACE_KEY" | jq -r '.results[] | select(.type=="page") | .id')
# Step 2: Iterate over each page ID and get the attachment download URLs
echo "Fetching attachment download links for each page..."
for page_id in $page_ids; do
echo "Processing Page ID: $page_id"
# Fetch attachments for the page
attachments=$(curl -s -u "$USERNAME:$PASSWORD" "$BASE_URL/rest/api/content/$page_id/child/attachment")
# Extract the download URLs using jq
download_links=$(echo "$attachments" | jq -r '.results[] | ._links.download')
# Check if there are any download links and process them
if [ -n "$download_links" ]; then
echo "Downloading attachments for Page ID $page_id..."
# Iterate through each download link and use wget to download the file
for link in $download_links; do
# Construct the full download URL by appending to the BASE_URL
full_url="$BASE_URL$link"
# Remove the query string section from the URL (anything after the `?`)
base_url=$(echo "$full_url" | sed 's/\?.*//')
# Use wget to download the file with basic authentication and additional flags
echo "Downloading $base_url..."
wget --user="$USERNAME" --password="$PASSWORD" --auth-no-challenge --trust-server-names --max-redirect=20 --header="User-Agent: Mozilla/5.0" "$base_url" -P ./$SPACE_KEY/downloads/
done
else
echo "No attachments found for Page ID $page_id."
fi
done
echo "Download completed."
The variables in the script should be filled out accordingly before executing it.
After the execution of the script the directory will be created with the space key and it will contain the downloaded attachments.
Attachments view
- From the page, click on the and select Attachments.
- Scroll to the bottom of the attachment list and click Download All.
Please note that browser extensions aren't supported by Atlassian.
Also, Chrome has a extension to download all attachments. Batch Link Download