Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I authenticate the call to get a Confluence page attachment?

Warren
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.
July 27, 2021

I have a standalone C# desktop application which gets the body of a Confluence page via an API call (using Basic authentication). 

Where there is an image (attachment) for the page, I pick up the _links.download URL which is used to download the attachment. I'm struggling with knowing how to authenticate this download, because it isn't a REST API call, but just a URL.

Does anyone have sample code (preferably C# or other .Net, but I'll try any language), which shows how to successfully download a Confluence attachment?

The code below is what I'm trying, but without authentication it gets garbage which isn't recognised as an image file

string imageUrl = "https://coname.atlassian.net/wiki" + attachment._links.download;
string saveLocation = @"D:\" + attachment.title;

byte[] imageBytes;
HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(imageUrl);
WebResponse imageResponse = imageRequest.GetResponse();
Stream responseStream = imageResponse.GetResponseStream();
using (BinaryReader br = new BinaryReader(responseStream))
{
imageBytes = br.ReadBytes(500000);
br.Close();
}
responseStream.Close();
imageResponse.Close();

File.WriteAllBytes(saveLocation, imageBytes);

 

1 answer

1 accepted

2 votes
Answer accepted
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 29, 2021

Hi Warren,

Thanks for raising this! I don't do a lot of programming myself, so I'm sorry that I don't have any suggestions.

So, if you don't get any suggestions here, I suggest the Atlassian Developer Community. They might be better able to help!

Take care,

Shannon

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events