gpt4 book ai didi

ibm-connections - IBM Connections API - 如何将文件附加到 wiki 页面?

转载 作者:行者123 更新时间:2023-12-01 00:57:53 26 4
gpt4 key购买 nike

在 IBM Connections 用户界面中,可以将文件直接附加到 wiki 页面。
我想以编程方式将文件附加到 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

专门查看文件和 Wiki 的 API,似乎没有关于 wiki 页面附件的内容。虽然我主要是想上传附件,但我什至看不到用于检索附件的文档化 API,尽管用户界面有一个链接到一个提要(在每个 wiki 页面上)这样做。

是否有任何(可能未记录的)API 将文件附加到 wiki 页面?

最佳答案

以下是一些示例代码,用于展示如何以受支持的方式执行此操作。

首先,您需要两个 URL。

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";

获取随机数
   /**
* 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>

关于ibm-connections - IBM Connections API - 如何将文件附加到 wiki 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26008911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com