1

The below code is working fine to attach file in JIRA, only one problem is here I can't use MultipartEntityBuilder as it needed to add new dependency in pom and that is not permissible , can any one please suggest which basic API I can use there? thanks in advance

CloseableHttpClient httpClient = HttpClientBuilder.create().build();

HttpPost postRequest = new HttpPost("https://xxxx.zzzz.net/rest/api/2/issue/" + issueID +"/attachments");
postRequest.setHeader("Authorization", "Basic <AUTHSTRING>");
postRequest.setHeader("X-Atlassian-Token", "nocheck");
File file = new File("C:\\Users\\MKumar\\Desktop\\Oauth_JIRA.rtf");
URL url = new URL("C:\\Users\\MKumar\\Desktop\\Oauth_JIRA.rtf");

MultipartEntityBuilder builder = MultipartBodyBuilder.create();

// This attaches the file to the POST:

builder.addBinaryBody(
    "file",
    new FileInputStream(file),
    ContentType.MULTIPART_FORM_DATA,
    file.getName()
);

HttpEntity multipart = builder.build();

postRequest.setEntity(multipart);

HttpResponse response = httpClient.execute(postRequest);
Mopendra Kumar
  • 71
  • 1
  • 12
  • 1
    NOTE (!): In the line starting with `postRequest.setHeader("Authorization"`, you had an authorization string that looks like the real username + password. It's just base64-encoded. That should never be posted publicly. I've edited it, but you should probably delete this question to remove it from the public history and re-post without the sensitive info. You may also want to change your Atlassian login info, since it may already be archived somewhere else by a crawler. – Chris Middleton Aug 04 '18 at 16:43

1 Answers1

1

org.apache.http.entity.mime.MultipartEntity is deprecated as a result you'll have to use MultipartEntityBuilder.

For more related post please see this thread

Praveen Shendge
  • 303
  • 3
  • 13