Hi
This code is working.
I can upload the attachment to the issue
String pathname= "screenshot-5.png";
File fileUpload = new File(pathname);
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost("https://XXX.atlassian.net/rest/api/2/issue/XXX-2/attachments");
BASE64Encoder base=new BASE64Encoder();
String encoding = base.encode ("username:password".getBytes());
postRequest.setHeader("Authorization", "Basic " + encoding);
postRequest.setHeader("X-Atlassian-Token","nocheck");
MultipartEntityBuilder entity=MultipartEntityBuilder.create();
entity.addPart("file", new FileBody(fileUpload));
postRequest.setEntity( entity.build());
HttpResponse response = httpClient.execute(postRequest);
System.out.println(response);
But I don't want to use my user name and password in my code .
I get API Token for my user

but i cant set the API Key to the httppost, I get
String pathname= "screenshot-5.png";
File fileUpload = new File(pathname);
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost("https://XXX.atlassian.net/rest/api/2/issue/XX-2/attachments");
postRequest.setHeader("Authorization", "Basic " + "OHi4Y7vowLxtgf456GNse4F0D");
postRequest.setHeader("X-Atlassian-Token","nocheck");
MultipartEntityBuilder entity=MultipartEntityBuilder.create();
entity.addPart("file", new FileBody(fileUpload));
postRequest.setEntity( entity.build());
HttpResponse response = httpClient.execute(postRequest);
System.out.println(response);
The response:
HttpResponseProxy{HTTP/1.1 404 [Server: Atlassian Proxy/1.13.6.2, Vary: Accept-Encoding, Cache-Control: no-cache, no-store, no-transform, Content-Type: application/json;charset=UTF-8, Strict-Transport-Security: max-age=315360000; includeSubDomains; preload, Date: Fri, 28 Dec 2018 13:54:05 GMT, ATL-TraceId: 3184af167d55799b, X-AREQUESTID: 55a30772-41f4-4469-931c-319bf1a3ea3f, X-XSS-Protection: 1; mode=block, Transfer-Encoding: chunked, Timing-Allow-Origin: *, X-AUSERNAME: anonymous, X-Content-Type-Options: nosniff, Connection: keep-alive, Set-Cookie: atlassian.xsrf.token=BVKF-A7NK-S2TE-5SA6_c2be0850c60dbef5983ed946da34a44559cfbe58_lout; Path=/; Secure] org.apache.http.client.entity.DecompressingEntity@35dab4eb}