JIRA REST API 损坏上传的 zip 附件

JIRA REST API corrupts uploaded zip attachment

我正在尝试使用 JIRA Rest API(版本 2)向问题添加 zip 附件。

代码似乎工作正常,但当我查看票证上的附件时,附件几乎是正常大小的两倍,在尝试打开它时我发现它已损坏。

我可以毫无问题地上传图像文件(在我的测试中是 png)。

我使用的代码是:

String basic = createBasicAuth();
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + basic);
headers.add("X-Atlassian-Token", "no-check");
headers.setContentType(MediaType.MULTIPART_FORM_DATA);

LinkedMultiValueMap<String, Resource> map = new LinkedMultiValueMap<>();
map.add("file", new ClassPathResource("/zipfile.zip"));

HttpEntity<LinkedMultiValueMap<String, Resource>> body = new HttpEntity<>(map, headers);

RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.postForEntity(jiraUrl, body, String.class);

我曾尝试使用 ByteArrayResource 而不是 ClassPathResource,但这会导致服务器出现 500 错误。

我还尝试将每个资源包装在它们自己的 HttpEntity 中,给定 zip 文件它自己的 headers,媒体类型设置为 application/octet-stream。

还有其他人遇到过这个问题吗?如果没有,我会用 Atlassian 记录它。 任何帮助都会很棒。

谢谢

原来这是 Spring (3.2.1) RestTemplate 或我如何使用它的问题。
使用 Postman 手动上传 zip 文件导致成功上传 zip 文件。