I am creating a C# application where i wish to download all the attachments from my page.
Also i wish to upload 2 documents at the same time from my C# app.
Can anybody share me some code ?
Hi Shaksham,
are you trying to download attachments from a Confluence Page?
Yes i have uploaded some .txt, .png files on my confluence page and i am trying to download all attachments via C# application. Pls help me out. Which api i should call..?
It depends on which version of Confluence you are using.
If you are using Confluence Cloud, the REST API docs are here:
https://developer.atlassian.com/cloud/confluence/rest/
Specifically, the attachment methods are here:
If you are using Confluence Server, the REST API docs are here:
https://docs.atlassian.com/atlassian-confluence/REST/6.6.0
You'll need to confirm the actual version of Confluence Server you're running and change that URL accordingly.
Specifically, the attachment methods are here: https://docs.atlassian.com/atlassian-confluence/REST/6.6.0/#content/{id}/child/attachment
@Marty Thanks for the answer.
Here is what i have tried till now but i am getting exception 302:
const string apiUrl = "https://connectpoc.atlassian.net/wiki/rest/api/content/98336/child/attachment"; var url = string.Empty; var pathToSave = string.Empty; Task.Run(async () => { var tracker = Stopwatch.StartNew(); using (var client = new HttpClient()) { var byteArray = Encoding.ASCII.GetBytes("myusername:password"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json"));var httpResponseMessageObj = await client.GetAsync(apiUrl); httpResponseMessageObj.EnsureSuccessStatusCode();HttpContent content = httpResponseMessageObj.Content;var data = await content .ReadAsStringAsync(); // return JSON Onlyvar result = JsonConvert.DeserializeObject<RootObject>(data); var baseurl = result._links.@base.ToString(); // Console.WriteLine(result); // var base=result.results[0]._links. var download = result.results[0]._links.download.ToString();url = baseurl + download; var filename = result.results[0].title; pathToSave = @C:\Reports\ + filename;var index = url.IndexOf("?", StringComparison.Ordinal);if (index > 0) url = url.Substring(0, index);var clients = new WebClient { Credentials = new NetworkCredential("username", "password") }; clients.DownloadData(url); // i am getting exception here "The remote server returned an error: (302) Moved Temporarily." return data; }}).Wait();
Can anybody tell me how to solve this issue i tried every code but still its not working.
Hi all, I got the solution for my above query
the only issue with the above code was replace below line
request.AddParameter(Path.GetFileNameWithoutExtension(fullFileName),filepath);
with
request.AddFile("file", entity.FilePath);
it must be AddFile when you posting a file i was using AddParameter.
AddFile Worked for me.
Thanks
It looks like you're new here. Sign in or register to get started.