官方链接:
The Jira Cloud platform REST API
POST
Add attachment
Adds one or more attachments to an issue. Attachments are posted as multipart/form-data (RFC 1867).
Note that:
- The request must have a
X-Atlassian-Token: no-check
header, if not it is blocked. See Special headers for more information. - The name of the multipart/form-data parameter that contains the attachments must be
file
.
The following examples upload a file called myfile.txt to the issue TEST-123:
curl
curl --location --request POST 'https://your-domain.atlassian.net/rest/api/2/issue/TEST-123/attachments'
-u 'email@example.com:<api_token>'
-H 'X-Atlassian-Token: no-check'
--form 'file=@"myfile.txt"'
java
// This code sample uses the 'Unirest' library:
// http://unirest.io/java.html
HttpResponse response = Unirest.post("https://your-domain.atlassian.net/rest/api/2/issue/{issueIdOrKey}/attachments")
.basicAuth("email@example.com", "")
.header("Accept", "application/json")
.header("X-Atlassian-Token", "no-check")
.field("file", new File("myfile.txt"))
.asJson();
System.out.println(response.getBody());