在IBM Connections用户界面中,可以将文件直接附加到Wiki页面 我想以编程方式将文件附加到维基页面,但无法找到记录的方法。
我一直在看这里的Connections 4.5 API文档:
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&content=catcontent&ct=prodDoc
专门研究文件和维基的API,似乎没有关于维基页面附件的内容。虽然我主要想要上传附件,但我甚至看不到用于检索附件的文档化API,尽管用户界面有一个指向Feed的链接(在每个维基页面上)。
是否有任何(可能是未记录的)API将文件附加到维基页面?
答案 0 :(得分:2)
以下是一些示例代码,用于说明如何以受支持的方式执行此操作。
首先,您需要两个网址。
private static String apiUrlWikiNonce = "https://sdkdev.swg.usma.ibm.com:444/wikis/basic/api/nonce";
private static String apiUrlWikiAttachment = "https://sdkdev.swg.usma.ibm.com:444/wikis/form/api/wiki/{WIKI_LABEL_OR_WIKI_UUID}/page/{PAGE_LABEL_OR_PAGE_UUID}/feed";
获取Nonce
/**
* gets the nonce value only valid return type is text, anything else throws
* an error
*
* @param httpClient
* @param user
* @param password
* @return
*/
public static String getNonce(CloseableHttpClient httpClient, String user,
String password) {
String result = "";
HttpGet httpGet = new HttpGet(apiUrlWikiNonce);
String combo = user + ":" + password;
String hash = org.apache.commons.codec.binary.Base64
.encodeBase64String(combo.getBytes());
System.out.println(user + " is logging in with " + hash);
String auth = "Basic " + hash;
httpGet.setHeader("Authorization", auth.replace("=", ""));
HttpClientContext context = HttpClientContext.create();
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpGet, context);
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
String responseString = writer.toString();
// System.out.println(responseString);
result = responseString;
EntityUtils.consume(entity);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
现在你有了诸如...之类的随机数... b1911872-36f1-4767-956d-214759886406
然后使用X-Update-Nonce上传文件
/**
* uploads a file to a given wiki page.
*
* @param httpClient
* @param user
* @param password
* @param wikiLabel
* @param wikiPage
* @param file
* @param nonce
* @return uuid <empty or uuid of file>
*/
public static String uploadFileToWiki(CloseableHttpClient httpClient, String user,
String password, String wikiLabel, String wikiPage, File file, String nonce){
String uuid = "";
String apiUrl = apiUrlWikiAttachment.replace("{WIKI_LABEL_OR_WIKI_UUID}", wikiLabel);
apiUrl = apiUrl.replace("{PAGE_LABEL_OR_PAGE_UUID}", wikiPage);
//Mandatory Parameter
apiUrl += "?category=attachment";
System.out.println("API Url : " + apiUrl);
HttpPost post = new HttpPost(apiUrl);
post.addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0");
post.addHeader("Content-Type", "image/png");
String combo = user + ":" + password;
String hash = org.apache.commons.codec.binary.Base64
.encodeBase64String(combo.getBytes());
System.out.println(user + " is logging in with " + hash);
String auth = "Basic " + hash;
post.setHeader("Authorization", auth.replace("=", ""));
HttpClientContext context = HttpClientContext.create();
CloseableHttpResponse response = null;
try {
EntityBuilder builder = EntityBuilder.create();
builder.setFile(file);
HttpEntity postentity = builder.build();
post.setHeader("Slug","NominalWorkItem-v1.png");
post.setHeader("title","Test Title");
post.setHeader("label","Test Test");
post.setEntity(postentity);
response = httpClient.execute(post, context);
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
String responseString = writer.toString();
System.out.println(responseString);
uuid = responseString;
EntityUtils.consume(entity);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return uuid;
}
文件已更新,您在创建时获得响应代码201和XML
> <?xml version="1.0" encoding="UTF-8"?><entry
> xmlns:thr="http://purl.org/syndication/thread/1.0"
> xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
> xmlns:snx="http://www.ibm.com/xmlns/prod/sn" xmlns:td="urn:ibm.com/td"
> xmlns="http://www.w3.org/2005/Atom"><id>urn:lsid:ibm.com:td:7780e11c-7240-41b3-8f0c-00a10ea69c93</id><td:uuid>7780e11c-7240-41b3-8f0c-00a10ea69c93</td:uuid><td:label>NominalWorkItem-v1.png</td:label><link
> href="https://sdkdev.swg.usma.ibm.com:444/wikis/form/api/wiki/744ccaeb-e9af-434c-9fa6-78831fb94846/page/3b017473-2dbe-4920-85a2-bf908a8e1475/attachment/7780e11c-7240-41b3-8f0c-00a10ea69c93/entry"
> rel="self"></link><link
> href="https://sdkdev.swg.usma.ibm.com:444/wikis/form/anonymous/api/wiki/744ccaeb-e9af-434c-9fa6-78831fb94846/page/3b017473-2dbe-4920-85a2-bf908a8e1475/attachment/7780e11c-7240-41b3-8f0c-00a10ea69c93/media/NominalWorkItem-v1.png"
> rel="alternate"></link><link
> href="https://sdkdev.swg.usma.ibm.com:444/wikis/form/api/wiki/744ccaeb-e9af-434c-9fa6-78831fb94846/page/3b017473-2dbe-4920-85a2-bf908a8e1475/attachment/7780e11c-7240-41b3-8f0c-00a10ea69c93/entry"
> rel="edit"></link><link
> href="https://sdkdev.swg.usma.ibm.com:444/wikis/form/api/wiki/744ccaeb-e9af-434c-9fa6-78831fb94846/page/3b017473-2dbe-4920-85a2-bf908a8e1475/attachment/7780e11c-7240-41b3-8f0c-00a10ea69c93/media"
> rel="edit-media"></link><link
> href="https://sdkdev.swg.usma.ibm.com:444/wikis/form/anonymous/api/wiki/744ccaeb-e9af-434c-9fa6-78831fb94846/page/3b017473-2dbe-4920-85a2-bf908a8e1475/attachment/7780e11c-7240-41b3-8f0c-00a10ea69c93/media/NominalWorkItem-v1.png"
> rel="enclosure" type="image/png" title="NominalWorkItem-v1.png"
> length="107763"></link><category term="attachment"
> scheme="tag:ibm.com,2006:td/type"
> label="attachment"></category><summary
> type="text"></summary><td:documentUuid>3b017473-2dbe-4920-85a2-bf908a8e1475</td:documentUuid><td:libraryId>744ccaeb-e9af-434c-9fa6-78831fb94846</td:libraryId><author><name>Frank
> Adams</name><snx:userid>6B54D23A-0A70-C7A4-8525-7CA50082A393</snx:userid><email>fadams@renovations.com</email><snx:userState>active</snx:userState></author><td:modifier><name>Frank
> Adams</name><snx:userid>6B54D23A-0A70-C7A4-8525-7CA50082A393</snx:userid><email>fadams@renovations.com</email><snx:userState>active</snx:userState></td:modifier><title
> type="text">NominalWorkItem-v1.png</title><published>2014-09-29T20:29:16.210Z</published><updated>2014-09-29T20:29:16.210Z</updated><td:created>2014-09-29T20:29:16.210Z</td:created><td:modified>2014-09-29T20:29:16.210Z</td:modified><td:lastAccessed></td:lastAccessed><content
> type="image/png"
> src="https://sdkdev.swg.usma.ibm.com:444/wikis/form/api/wiki/744ccaeb-e9af-434c-9fa6-78831fb94846/page/3b017473-2dbe-4920-85a2-bf908a8e1475/attachment/7780e11c-7240-41b3-8f0c-00a10ea69c93/media"></content></entry>
答案 1 :(得分:1)
我认为可以通过多部分帖子来实现这一点,但在我自己的代码中,我是按步骤进行的:
网址:
https://<Server>/<Wikis-Context-Root>/basic/api/wiki/<wikiUuid>/page/<pageUuid>/feed
内容:强>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:td="urn:ibm.com/td">
<category label="attachment" scheme="tag:ibm.com,2006:td/type" term="attachment"/>
<td:label>file_name.extension</td:label>
</entry>
标题:
Content-Type: <file mime-type, e.g. IMAGE/JPG>
Slug: <file_name.extension>
回复:201;位置:附件条目的URL
网址位置响应 - 之前回复的标头,仅替换“/ media”的最后一个“/条目”
内容:文件内容流
<强>接头强>
Content-Type: <Mime-Type>
回复:200或201
网址位置响应 - 来自1的请求标头。)
内容:强>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:td="urn:ibm.com/td">
<category label="attachment" scheme="tag:ibm.com,2006:td/type" term="attachment"/>
<summary type="text">MY ATTACHMENT DESCRIPTION TEXT</summary>
<td:label>file_name.extension</td:label>
</entry>
<强>接头强>
Content-Type: application/atom+xml
回复:200或201