How can a Confluence User Download all Attachments in a Space?

Angie Affolter
Contributor
December 12, 2019

Each client project is in a space and when the project is over, we need to be able to have them download the attachments without going page by page.  The Pages we can export to one PDF file but no solution for attachments.

2 answers

0 votes
Karol Michalik
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 21, 2023

I will just add that if you want the files to be separately as files you can do that and ensure they have descriptive names. (and not face a problem with PDF export with certain types of  attachments due to embed) there is another way.

  1. Space tools > Content Tools 
  2. Find the Export tab
  3. xml export (this gives us neat xml file with id mapped to name)
  4. . Do a HTML export (this gives us files named with IDs to match the ID in above xml file)
  5. Then I ran python script to simply rename the attachments so can be easily identified. (I am taking no responsibility for the code below not working or working improperly on end machine):

 

import os
import xml.etree.ElementTree as ET

# Path to the directory where the files are saved
directory_path = r"path\to\html\export\attachments\folder"

# Path to the XML file
xml_file_path = r"path\to\file.xml"

# Parse the XML file
tree = ET.parse(xml_file_path)
root = tree.getroot()

# Create a dictionary to store file IDs and real names
file_dict = {}

# Extract file IDs and real names from the XML
for attachment in root.iter('object'):
attachment_class = attachment.attrib.get("class")
if attachment_class == "Attachment":
file_id = attachment.find("./id[@name='id']").text
real_name = attachment.find("./property[@name='title']").text
file_dict[file_id] = real_name

# Rename files in place
for root_folder, _, files in os.walk(directory_path):
# Create a dictionary to track counts of each file name in a directory
name_count = {}

for filename in files:
file_id, file_extension = os.path.splitext(filename)

# Check if the file ID exists in the dictionary
if file_id in file_dict:
real_name = file_dict[file_id]
base_name, ext = os.path.splitext(real_name)

# Check if the file name already exists in the directory
if base_name in name_count:
name_count[base_name] += 1
new_base_name = f"{base_name}_{name_count[base_name]}"
else:
new_base_name = base_name

name_count.setdefault(base_name, 1)

new_name = f"{new_base_name}{ext}"
old_path = os.path.join(root_folder, filename)
new_path = os.path.join(root_folder, new_name)

# Rename the file
os.rename(old_path, new_path)
print(f"Renamed: {old_path} -> {new_path}")
0 votes
Thomas B
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.
December 16, 2019

Hello @Angie Affolter - it's still pretty manual, but better than exporting page by page. I see two options:

Option 1 (formats space and supported attachments as pages)

  1. Space tools > Content Tools 
  2. Find the Export tab
  3. Export the Space as PDF
  4. Select Next > Normal Export
  5. Your PDF will be your entire space, including attachments (if supported)

Option 2 (manual export of each attachment)

  1. Space tools > Content Tools
  2. Find the Attachments tab
  3. Clicking on each attachment will start a download

Please let me know if this resolves your issue, or if you have additional questions!

Angie Affolter
Contributor
December 18, 2019

Thanks!  That's what I was doing.  I was hoping for a more user-friendly answer. 

My IT guys found this info - not end user but might be a good alternative:

https://community.atlassian.com/t5/Confluence-questions/Export-spaces-and-attachments/qaq-p/135920

https://bobswift.atlassian.net/wiki/spaces/CSOAP/pages/177373303/How+to+download+all+attachments+for+a+space

Victor Prasad
Contributor
March 9, 2022

PDF shows this on the version of Confluence I am using.  7.4.7.  is there an option to get the attachments?

 

Export PDF Options

 

 

Normal Export
Generates a PDF file for each page in this space, excluding blogs, comments, and attachments.
Adam Rypel _MoroSystems_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2022

Hello @Victor Prasad ,

you can export as XML and you will get also the attachments in the export.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events