Accessing attachments via the REST API using C#

HLH June 17, 2021

Hi, I'm trying to access the attachments in JIRA Software via the REST API. I can access the URL but I'm trying to get the contents of the URL and display it on a webpage. I think I'm getting a bit confused and was hoping someone could help! 

The url comes from the API but it's easier just to put it in as a string here to show you what I've been doing so far! 

string url= "https://www.myurl.com/secure/attachment/13149/image-2019-04-02-16-25-18-458.png";  
WebRequest myReq = WebRequest.Create(url);
string credentials = "username:pwd";
CredentialCache mycache = new CredentialCache();
myReq.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials));
myReq.Method = "GET";
myReq.ContentType = "image/png";
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();

 

Could anyone show me examples or give me some help as to what the next step should be after retrieving the file? 

0 answers

Suggest an answer

Log in or Sign up to answer