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);
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.