Hi,
We are creating a tool to migrate Versionone data to JIRA. So for this I am consuming REST APIs mentioned in "https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-issue-issueIdOrKey-remotelink-linkId-put". I am struggling to upload an attachment to an issue. All the time I am getting Statuscode as "200" but there is no attachment to the issue in JIRA. Here in below is my code, please suggest me what I am doing wrong here.
Snippet
SendFileToServer("XYZ-315");Snippet
private void SendFileToServer(string IssueKey)
{
FileInfo fi = new FileInfo(@C:\VersionOneAttachments\some.png);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
byte[] fileContents = File.ReadAllBytes(fi.FullName);
//https://your-domain.atlassian.net/rest/api/2/issue/XYZ-315/attachments
string urlPath = ConfigurationSettings.AppSettings.Get("JIRAURLForCreateIssue").ToString();
Uri webService = new Uri(string.Format("{0}/{1}/attachments", urlPath, IssueKey));
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, webService);
requestMessage.Headers.ExpectContinue = false;
MultipartFormDataContent multiPartContent = new MultipartFormDataContent("----MyGreatBoundary");
ByteArrayContent byteArrayContent = new ByteArrayContent(fileContents);
byteArrayContent.Headers.Add("Content-Type", "image/png");
byteArrayContent.Headers.Add("X-Atlassian-Token", "no-check");
multiPartContent.Add(byteArrayContent, "this is the name of the content", fi.Name);
requestMessage.Content = multiPartContent;
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Authorization", ConfigurationSettings.AppSettings.Get("JiraAuthorizationKey").ToString());
httpClient.DefaultRequestHeaders.Add("X-Atlassian-Token", "no-check");
try
{
Task<HttpResponseMessage> httpRequest = httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
HttpResponseMessage httpResponse = httpRequest.Result;
HttpStatusCode statusCode = httpResponse.StatusCode;
HttpContent responseContent = httpResponse.Content;
if (responseContent != null)
{
Task<String> stringContentsTask = responseContent.ReadAsStringAsync();
String stringContents = stringContentsTask.Result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Any idea will be appreciated.
Thanks in advance
Basanta Padhi