How to download a file attached in confluence page
Asked by Georgios Taskos:

I'm a little bit confused with the REST API documentation.

Say I have a confluence page

https://COMPANY_DOMAIN/confluence/display/SOME_ID/This+is+root+page.

In the above page there is a section with a hyperlink like the below

https://COMPANY_DOMAIN/confluence/download/attachments/51527290/FileName

Reading a little bit around I found [an answer](https://community.atlassian.com/t5/Answers-Developer-Questions/confluence-pages-get-attached-files-via-REST-API/qaq-p/529873) implying that with this https://COMPANY_DOMAIN/rest/api/content/{id}/child/attachment I could download the file but not sure what the actual id is.

I tried with a GET and adding Authorization header with my company credentials.

Any ideas or examples?


Answers:
author: Thomas Deiler
body: Dear [@Georgios Taskos](/t5/user/viewprofilepage/user-id/1154765),

nearly everything you need is written in the upper article.

First you need a list of all attachments (can also be only one) of one page.This is done via Rest:

```
GET /rest/api/content/{id}/child/attachment
```

The {id} is the internal number of your page. You can see this when you click on ++Page Information++.

In the JSON response you have to look for the attachment and remember its

```
_links -> download
```

value. Then you need to make a normal HTTP call to download the file.

```
http://localhost:8090/download/attachments/98334/my_attachment.pdf?version=1&amp;modificationDate=1451988725383&amp;api=v2
```

There the authentication works different as for a rest call, when not running from the browser. Read this [post](https://community.atlassian.com/t5/Jira-questions/Retrieving-Member-Avatar-File-via-API/qaq-p/714489#M233762). Its for Jira, but it works the same way for Confluence.

So long

Thomas

comments: author: Thomas Deiler
body: Dear [@Georgios Taskos](/t5/user/viewprofilepage/user-id/1154765),

you didn't come back to this question. Have you solved your problem? Do you need still assistance?

So long

Thomas


author: Rahul Purohit
body: I am unable to list attachments of a page like you said.

I got 404 after hitting

https://\<comapny-domain\>/rest/content/\<page-id\>/child/attachment


author: Thomas Deiler
body: Dear [@Rahul_Purohit](/t5/user/viewprofilepage/user-id/377173) ,

there was a typo - I fixed in my answer:

False:

```
https://<comapny-domain>/rest/content/<page-id>/child/attachment
```

True:

```
https://<comapny-domain>/rest/api/content/<page-id>/child/attachment
```

So long

Thomas


author: NISARG SONI
body: [@Thomas Deiler](/t5/user/viewprofilepage/user-id/484715)

The following curl command to GET a list of attachment with their 'result' worked where I am getting a 'result' of attachment.

curl -X GET -H "Authorization: Basic BASE64CODE" -H "X-Atlassian-Token: nocheck" https://\<COMPANY_DOMAIN\>/rest/api/content/\<pg-id\>/child/attachment?filename=\<filename\>

However, I am trying to download an attachment.

In result with multiple parameters of attachment, I am seeing download part...

```
"download":"/download/attachments/<pg-id>/<filename>?version=59&modificationDate=1641419542563&api=v2"
```

I would like to download this attachment in remote host.

Can you please help me figure out the EXACT curl command to download the file in REMOTE HOST directory (hostname@//home/backup/)

Let me know please.

Thanks

Nisarg


author: Thomas Deiler
body: Dear [@NISARG SONI](/t5/user/viewprofilepage/user-id/4696415) ,

welcome to the community!

Please do as described in my post from Feb 1, 2018:

* first fetching all attachment information of one page
* then simple take the download link (it's in the JSON response) to get one attachment

The curl command is

```
curl -H "Authorization: Basic ....." <download link>
```

So long

Thomas D


author: NISARG SONI
body: Hello [@Thomas Deiler](/t5/user/viewprofilepage/user-id/484715)

I ran the following command and it shows me file data in the remote server itself.

curl -H "Authorization: Basic BASE64CODE" https://\<COMPANY_DOMAIN\>(/download/attachments/\<pg-id\>/\<filename\>?

However, I would like to SAVE the exact file with same format in remote server in some directory (Let's say //home/backup)

Regards,

Nisarg


author: NISARG SONI
body: Hello [@Thomas Deiler](/t5/user/viewprofilepage/user-id/484715)

I just figured out the way to download and save it in remote server. Here is the curl command:

curl -H "Authorization: Basic BASE64CODE" https://\<COMPANY_DOMAIN\>/download/attachments/\<pg-id\>/\<filename\>? -o //home/backup/\<filename\>

Thanks

Nisarg


author: Toru Furuya
body: Hi, I got the download link URL from the REST API response and am trying to download the file but having trouble.

What am I missing? The below request returns a 302 HTTP response with a \`location\` response header that seems to point to the exact location of the file

```
curl -u <email>:<api_token> "https://<domain>/wiki/download/attachments/2534081977/<file>.zip?version=1&modificationDate=1643705591470&cacheVersion=1&api=v2"
```


author: April Dagonese
body: [@Toru Furuya](/t5/user/viewprofilepage/user-id/2515536) did you ever figure this out? I'm having a similar issue using an oauth2 token except I'm just getting back 401s instead.


Tags: atl-gruland

attachment

developer