2
我希望通过POST请求向JIRA上传视频文件(.mp4)。文件被上传到服务器,但视频被破坏(即打开它不起作用)。发送其他附件,如截图(.png)和文本文件(.txt),可以正常工作而不会破坏文件。通过REST API将视频文件发送给Java中的JIRA
我使用Apache HttpComponents HttpClient 4.3.6。
下面是示例代码:
File file = new File("location/to/file.mp4");
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create().addBinaryBody("file", file);
HttpPost postRequest = new HttpPost();
postRequest.addHeader(HttpHeaders.AUTHORIZATION, BASIC_AUTH);
postRequest.addHeader("X-Atlassian-Token", "nocheck");
postRequest.setEntity(multipartEntity.build());
postRequest.setURI(uri);
CloseableHttpClient client = HttpClients.createDefault();
try {
HttpResponse response = client.execute(request);
} finally {
client.close();
}
我试图添加一个video/mp4
MIME类型,但似乎并没有帮助任何:
MultipartEntityBuilder.create().addBinaryBody("file", file, ContentType.create("video/mp4"), file.getName())