Forums

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

How to Add Attachment in Jira Issue using C#

Hamed Deshmukh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 26, 2022

I have tried this code but it is not working....

string url = $"http://jiraurl/rest/api/2/issue/{key}/attachments";
var client = new HttpClient();
var header = new AuthenticationHeaderValue("Basic", Password);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Authorization = header;
client.DefaultRequestHeaders.Add("X-Atlassian-Token", "no-check");

MultipartFormDataContent multiPartContent = new MultipartFormDataContent("-data-");
FileInfo fi = new(@"D:/CSN/Process Project Request.pdf");
ByteArrayContent byteArrayContent;
using (var ms = new MemoryStream())
{
fi.CopyTo("abc");
var fileBytes = ms.ToArray();
//string fileString = Convert.ToBase64String(fileBytes);
byteArrayContent = new ByteArrayContent(fileBytes);
}

multiPartContent.Add(byteArrayContent, "file", fi.FullName);

var response = await client.PostAsync(url, multiPartContent);

var result = response.Content.ReadAsStringAsync().Result;

if (response.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception(result);

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events