It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

JIRA REST API Attachment incoherent result

Hi,

I'm trying to attach files by using the JIRA REST API on JIRA 5.

JIRA returns the 200 HTTP code, so it means everything worked fine (?) Nevertheless, the attached files are missing. No information about what happened neither in the log file nor anywhere.

However, it worked by uploading the files from the JIRA web client . Even worked fine by using the curl client. But NOT by using the Java HttpClient (logged in, added the X-Atlassian-Token: nocheck header, image/jpeg mime type and so on... those all details were reviewed)

Why does JIRA do? Why does it return 200?

Thanks,

Pablo.

2 answers

I've found the... bug? or the poor implemetation? of the RFC 1867 on JIRA while inspecting the multipart output

curl:

>> Content-Disposition: form-data; name="file"; filename="Project Requirements.doc_page_6_6.jpg"
>> Content-Type: image/jpeg

HttpClient:

>> Content-Disposition: form-data; name="other thant file"; filename="Software Requirements Specification.doc_page_6_6.jpg"
>> Content-Type: image/jpeg; charset=UTF-8
>> Content-Transfer-Encoding: binary

JIRA requires that the name (InputType) be file. Likely, JIRA suports other names ( input types) as attachments but anyway JIRA should respond with a 400 code (Bad Request) rather than 200 (OK) whether a not recognized input type is sent from any client.
Moreover, the REST API documentation should notice about it, because curls automatically sets the name to file, but other clients give freedom to developers to set it.


					
				
			
			
			
				
			
			
			
			
			
			
		

Thanks! This was the exact problem I was having using Postman. In the form-data body the "Key" field for my attachment needs to be "file", this maps exactly to the name attribute. I was getting 200 OK but the file was not being uploaded. I typed "file" into the "Key" field for the attachment and now it's working.

Thank you so much! This did the trick for me :)

...

MultiPart multiPart = new MultiPart();
FormDataContentDisposition formDataContentDisposition = FormDataContentDisposition.name("file").fileName(FILENAME).build();
multiPart.setContentDisposition(formDataContentDisposition);
multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file",
new File(getClass().getClassLoader().getResource("FILENAME).getFile()),
MediaType.APPLICATION_OCTET_STREAM_TYPE);
multiPart.bodyPart(fileDataBodyPart);

...

Headers taken from curl output:

> POST /jira/rest/api/latest/issue/TEST-39/attachments HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: toshi:2990
> Accept: */*
> X-Atlassian-Token: nocheck
> Content-Length: 8112
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------f60a0cc2c9ef

Headers taken from HttpClient output:

>> POST /jira/rest/api/latest/issue/TEST-39/attachments HTTP/1.1
>> Cookie: $Version=0; atlassian.xsrf.token=BP8Q-WXN6-SKX3-NB5M|cf5b539374e2a1434882067e95c46d1eb801ce50|lout; $Path=/jira
>> Cookie: $Version=0; JSESSIONID=7FE086588C53827CF7B4B70FCAC777B7; $Path=/
>> User-Agent: Jakarta Commons-HttpClient/3.1
>> Host: toshi:2990
>> X-Atlassian-Token: nocheck
>> Content-Length: 10186
>> Expect: 100-continue
>> Content-Type: multipart/form-data; boundary=Et-PrNk5xMYZkRDRSR9vMoLzqhFQVfsMGahEm1S

Both are equivalent and JIRA sends back:

HTTP/1.1 100 Continue

Then both, curl and httpclient upload the file data and receive a

HTTP/1.1 200 OK

HttpClient 3.1 is multipart/form-data RFC 1867 compliant, so I don't see much reasons about the JIRA behaviour.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

We want to hear from you! How do you use Slack and Atlassian together?

Hi Everyone! My name is Mina and I am on Atlassian’s Ecosystems Marketing team. Our team is focused on our technology partnerships and marketplace apps. One of Atlassian’s partners is Slack, who ...

85 views 1 5
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you