java - 带有 REST API 的文件附件
问题描述
下面的代码可以很好地在 JIRA 中附加文件,只有一个问题是我不能使用 MultipartEntityBuilder,因为它需要在 pom 中添加新的依赖项,这是不允许的,任何人都可以建议我可以在那里使用哪个基本 API ? 提前致谢
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);
解决方案
org.apache.http.entity.mime.MultipartEntity已被弃用,因此您必须使用MultipartEntityBuilder。
有关更多相关帖子,请参阅此线程
推荐阅读
- sharepoint - 以 webParts 形式查询图像的详细信息
- json - go中json序列化后的匿名结构
- vba - 在插入的单词后移动光标
- google-maps - 我可以强制 Google 地理编码 API 在地理编码请求中包含邮政编码吗?
- html - 登录路由过程
- swift - 自定义下拉菜单动画乱七八糟?
- python - django rest framework 如何删除多余的查询?
- mongodb - 如何在mongodb中使用$pull删除之前进行备份?
- ruby - 多个链式查找器导致选择根节点
- node.js - AWS serverless-image-handler v3.x 因 AWS Lambda 执行环境的更改而中断