我想將圖像發佈到作爲附件的內容的合流頁面。用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