Hi,
I need to attach a file to particular issue by using REST API. Please provide Json REST API.
Now i am able to attach a file to JIRA issue attachment section by changing the below code block,
var filename = "C:\\Users\\XXXX\\Desktop\\Sample.xlsx"; var file_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; var filecontent = new ByteArrayContent(System.IO.File.ReadAllBytes(filename)); var content = new MultipartContent("form-data", "AAAA"); content.Headers.Add("X-Atlassian-Token", "nocheck"); content.Headers.Add("charset", "UTF-8"); filecontent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data") { Name="\"file\"", FileName = "Attachment.xlsx" }; filecontent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(file_type); content.Add(filecontent);
You can try the simple curl command below by change the relative information:
curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" http://myhost/rest/api/2/issue/TEST-123/attachments
For more information, you can refer to the rest api documentation: https://docs.atlassian.com/jira/REST/latest/#id167611
HI Teck,
Thank for replay. please share the Json file for this operation, below REST API JSON is ok or not
{ "fields": { "attachments":[ "filename": "D:\xx.txt" ] } }
Hey Srini, you don't need the json file to attach the attachment. You can directly point to the file location in the file parameter of the request. Example:
curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@D:\xxx.txt" http://localhost:8080/rest/api/2/issue/TEST-1/attachment
Hi Tech,
I need to attach 10 files to JIRA issue, how can i achieve this programmatically by using REST API? i not using Curl command.
I have been working with Jira API and have seen inconsistent results for my requests over and over again. Sometimes it works and sometimes it doesn't. Last week I was able to post attachments to issues just fine, but now an old problem occurred: the names of the attachments contain the whole path of the posted file, hence the attachments can't be opened. I use json representation to post files:
$array = array("file"=>"@filename");
json_encode($array);
...
This gets the file posted but the problem is when it's posted the file names in JIRA are like this:
> /var/www/user/text.text
needless to say it can't be opened in JIRA. I had this problem before, then it suddenly disappeared, now it occurred again. I don't really get it. By the way I am not using curl for this request even though it might be recommended in the documentation.
I would appreciate it if you could help me
Best regards,
Thao
It looks like you're new here. Sign in or register to get started.