我想将图像发布到作为附件的内容的合流页面。用Java和Apache发布附件到confluence时得到了404 HttpClient
这是我的Java应用程序的功能:
public void postAttachment(File f, String comment) throws IOException {
if (!f.exists() || !f.canRead()) {
throw new IOException("Could not access file " + f.getAbsolutePath());
}
final FileBody bin = new FileBody(f);
final StringBody cmt = new StringBody(comment, ContentType.TEXT_PLAIN);
final HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("file", bin).addPart("comment", cmt).build();
final HttpPost post = new HttpPost(baseUrl + "/rest/api/content/" + contentid + "/child/attachment");
post.setEntity(reqEntity);
post.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(props.getString("confluence_user"),props.getString("confluence_password")), "UTF-8", false));
post.addHeader("X-Atlassian-Token:","no-check");
System.out.println("executing request " + post.getRequestLine());
final CloseableHttpClient httpclient = HttpClients.createDefault();
final CloseableHttpResponse response = httpclient.execute(post);
System.out.println(post.getRequestLine());
System.out.println(response.toString());
if (response.getStatusLine().getStatusCode() == 404) {
throw new IOException("Status 404 thrown!");
}
}
在终端的输出是:
POST https://xxx.xxxx.de:443/rest/api/content/38262140/child/attachment
然后
HttpResponseProxy{HTTP/1.1 404 Not Found [Server: Apache-Coyote/1.1, X-ASEN: SEN-1343236, Set-Cookie: JSESSIONID=9DF46011711C2828977E17A945D023E1; Path=/; Secure; HttpOnly, X-Seraph-LoginReason: OK, X-AUSERNAME: xxxx, X-Content-Type-Options: nosniff, Content-Type: text/plain, Transfer-Encoding: chunked, Date: Tue, 27 Sep 2016 11:20:35 GMT] ResponseEntityProxy{[Content-Type: text/plain,Chunked: true]}}
(I改变了域名和用户名只是这个职位..)
所以一切似乎都没问题。如果我复制生成的POST URL并在浏览器中执行GET操作,我会得到一个带附件列表的json片段,之前手动上传。所以POST网址应该没问题。
我在网上搜索,但我找不到我的代码错在哪里..任何建议?
从文档: 状态404:返回,如果请求的内容不发现该用户没有查看权限,或者附件超过了最大配置的附件大小。 https://docs.atlassian.com/confluence/REST/latest/#content/{id}/child/attachment-createAttachments – mtheriault
非常感谢您的评论。使用同一个用户,我可以在Web界面中手动创建相同的附件。我的约150 kb大..所以不幸我不认为这是问题。我还使用另一个(第三方)应用程序生成相同的内容,所以我不认为它的权限或附件大小问题。 – DaHopi
好奇心,你能够使用GET获取页面 - https:// xxx.xxxx.de:443/rest/api/content/38262140? – mtheriault