0

The postman works in the below format to upload an attachment.

set method type to POST.

Then select Body -> form-data -> Enter your parameter name

and on right side next to value column, there will be dropdown "text, file", select File. choose your image file and post it:

postman screenshot

I succeed with form-data, how do achieve via RAW text or Json because the image which is uploaded is dynamic.The image and txt file is stored in my local.

I am trying to upload png and .txt file to JIRA Rest endpoint(Subtask). My goal is create subtask, once subtask is created add attachment to it, attachment can be dynamic.

curl -X POST \
  https://host/rest/api/3/issue/pos-14108/attachments \
  -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'Postman-Token: c2b02ef1-4b81-4e8e-bb02-fb697bb2680e,1c20aa55-27c5-44c3-9f08-7efc41f25576' \
  -H 'X-Atlassian-Token: no-check' \
  -H 'cache-control: no-cache,no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F file=@/Users/nmane/Desktop/harry.png
Adil B
  • 14,635
  • 11
  • 60
  • 78
Nitin Mane
  • 23
  • 1
  • 5
  • just to clarify: So the issue is that Jira is corrupting the file? or that postman doesn't send it? or something completely different? – JoSSte Oct 23 '18 at 13:17
  • I succeed with form-data but not with passing data in raw JSON format. The following raw json format which i tried {"file": { "name": "/Users/nmane/Downloads/jira.png", "content-type":"image/png", "file":"base64string"}}. Results in Status:415 Unsupported Media Type. – Nitin Mane Oct 23 '18 at 13:47

1 Answers1

1

According to this article on the Jira forums, to add an attachment, you should do the following:

curl -D- -u {username}:{password} -X POST -H "X-Atlassian-Token: nocheck" -F "file=@{path/to/file}" http://{base-url}/rest/api/2/issue/{issue-key}/attachments

according to Using curl to upload POST data with files

That fits with your comments and experiences, as far as I can tell.

I have not encountered anything about attaching files to a "raw" JSON request. The only way to do something like that would be to base 64 encode it (see Is it possible to attach file in POST Json? ) but I do not think that the Jira REST API supports it.

I hope that I have understood your issue correctly. if not, and you actually (for some reason) want to run everything from postman/newman, please update your question.

JoSSte
  • 2,953
  • 6
  • 34
  • 54