How can a Confluence User Download all Attachments in a Space?
Asked by Angie Affolter:

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.


Answers:
author: Karol Michalik
body: 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}")
```


author: Thomas B
body: Hello [@Angie Affolter](/t5/user/viewprofilepage/user-id/1532680) - 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!

comments: author: Angie Affolter
body: 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>


author: Victor Prasad
body: 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 {#toc-hId--1181683383}
-----------------------------------------

Normal Export  
Generates a PDF file for each page in this space, **excluding blogs, comments, and attachments.**


author: Adam Rypel _MoroSystems_
body: Hello [@Victor Prasad](/t5/user/viewprofilepage/user-id/752839) ,

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


Tags: confluence-server

server