ibm连接将文件分配给文件夹
ibm connections assigning file to folder
当我尝试分配一个带文件夹的文件时遇到问题,文件和文件夹存在于系统中,但是当我使用上传文件文件夹的方法时,响应成功,但文件不正确文件夹。
我用的方法
POST /basic/api/collection/{collection-id}/feed
在集合 ID 中,我更改了文件夹 UUID,但不起作用。
你知道如何将文件分配到文件夹吗?
System.out.println("Uploading " + fileName + " in " + parentFolderName);
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
Entry entry = factory.newEntry();
//Entry
entry.setTitle(parentFolderName);
entry.setId(parentFolderUUID);
InputStream in = req.getInputStream();
entry.setContent("application/pdf");
entry.setLanguage("en");
AbderaClient abderaClient = new AbderaClient(abdera);
abderaClient.addCredentials(Utils.configJson.getString("connectionsServerURL"), null, null, new UsernamePasswordCredentials(connectionsUser, connectionsPassword));
//Nonce
String nonceUrl = "https://connectionsww.demos.ibm.com/files/basic/api/nonce";
ClientResponse respNonce = abderaClient.get(nonceUrl);
StringWriter writerNonce = new StringWriter();
IOUtils.copy(respNonce.getInputStream(), writerNonce, "UTF-8");
String nonce = writerNonce.toString();
//Multipart-post options
RequestOptions options = abderaClient.getDefaultRequestOptions();
options.setSlug(parentFolderUUID);
options.setContentType("multipart/mixed");
options.setAcceptLanguage("en");
options.setHeader("X-Update-Nonce", nonce);
fileURL = fileURL + "?X-Update-Nonce=" + nonce;
ClientResponse resp = abderaClient.post(fileURL, entry);
根据方法签名,我认为您缺少两项:
一个
Content-Type header 应该是
Content-Type: application/atom+xml
itemid的两个payload(id里面是我要的文件的id在folder/collection)。
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<itemId xmlns="urn:ibm.com/td">aca70bd1-0925-42c1-8196-b1c3042178a6</itemId>
</entry>
</feed>
我找到了@Paul 的答案的解决方案,它在那里的最终代码。
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
Entry entry = factory.newEntry();
//Entry
entry.setUpdated(new java.util.Date());
entry.setTitle(parentFolderName);
entry.setId(parentFolderUUID);
InputStream in = req.getInputStream();
entry.setContent("application/atom+xml");
entry.setLanguage("en");
AbderaClient abderaClient = new AbderaClient(abdera);
abderaClient.addCredentials(Utils.configJson.getString("connectionsServerURL"), null, null, new UsernamePasswordCredentials(connectionsUser, connectionsPassword));
System.out.println("added abdera client credentials");
//Nonce
String nonceUrl = "https://connectionsww.demos.ibm.com/files/basic/api/nonce";
ClientResponse respNonce = abderaClient.get(nonceUrl);
StringWriter writerNonce = new StringWriter();
IOUtils.copy(respNonce.getInputStream(), writerNonce, "UTF-8");
String nonce = writerNonce.toString();
//Multipart-post options
RequestOptions options = abderaClient.getDefaultRequestOptions();
options.setSlug(parentFolderUUID);
options.setContentType("application/atom+xml");
options.setAcceptLanguage("en");
options.setHeader("itemId", docUUID);
fileURL = fileURL + "?itemId="+docUUID;
System.out.println("fileURL+++++: " + fileURL);
ClientResponse resp = abderaClient.post(fileURL, entry, options);
当我尝试分配一个带文件夹的文件时遇到问题,文件和文件夹存在于系统中,但是当我使用上传文件文件夹的方法时,响应成功,但文件不正确文件夹。
我用的方法
POST /basic/api/collection/{collection-id}/feed
在集合 ID 中,我更改了文件夹 UUID,但不起作用。
你知道如何将文件分配到文件夹吗?
System.out.println("Uploading " + fileName + " in " + parentFolderName);
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
Entry entry = factory.newEntry();
//Entry
entry.setTitle(parentFolderName);
entry.setId(parentFolderUUID);
InputStream in = req.getInputStream();
entry.setContent("application/pdf");
entry.setLanguage("en");
AbderaClient abderaClient = new AbderaClient(abdera);
abderaClient.addCredentials(Utils.configJson.getString("connectionsServerURL"), null, null, new UsernamePasswordCredentials(connectionsUser, connectionsPassword));
//Nonce
String nonceUrl = "https://connectionsww.demos.ibm.com/files/basic/api/nonce";
ClientResponse respNonce = abderaClient.get(nonceUrl);
StringWriter writerNonce = new StringWriter();
IOUtils.copy(respNonce.getInputStream(), writerNonce, "UTF-8");
String nonce = writerNonce.toString();
//Multipart-post options
RequestOptions options = abderaClient.getDefaultRequestOptions();
options.setSlug(parentFolderUUID);
options.setContentType("multipart/mixed");
options.setAcceptLanguage("en");
options.setHeader("X-Update-Nonce", nonce);
fileURL = fileURL + "?X-Update-Nonce=" + nonce;
ClientResponse resp = abderaClient.post(fileURL, entry);
根据方法签名,我认为您缺少两项:
一个 Content-Type header 应该是
Content-Type: application/atom+xml
itemid的两个payload(id里面是我要的文件的id在folder/collection)。
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<itemId xmlns="urn:ibm.com/td">aca70bd1-0925-42c1-8196-b1c3042178a6</itemId>
</entry>
</feed>
我找到了@Paul 的答案的解决方案,它在那里的最终代码。
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
Entry entry = factory.newEntry();
//Entry
entry.setUpdated(new java.util.Date());
entry.setTitle(parentFolderName);
entry.setId(parentFolderUUID);
InputStream in = req.getInputStream();
entry.setContent("application/atom+xml");
entry.setLanguage("en");
AbderaClient abderaClient = new AbderaClient(abdera);
abderaClient.addCredentials(Utils.configJson.getString("connectionsServerURL"), null, null, new UsernamePasswordCredentials(connectionsUser, connectionsPassword));
System.out.println("added abdera client credentials");
//Nonce
String nonceUrl = "https://connectionsww.demos.ibm.com/files/basic/api/nonce";
ClientResponse respNonce = abderaClient.get(nonceUrl);
StringWriter writerNonce = new StringWriter();
IOUtils.copy(respNonce.getInputStream(), writerNonce, "UTF-8");
String nonce = writerNonce.toString();
//Multipart-post options
RequestOptions options = abderaClient.getDefaultRequestOptions();
options.setSlug(parentFolderUUID);
options.setContentType("application/atom+xml");
options.setAcceptLanguage("en");
options.setHeader("itemId", docUUID);
fileURL = fileURL + "?itemId="+docUUID;
System.out.println("fileURL+++++: " + fileURL);
ClientResponse resp = abderaClient.post(fileURL, entry, options);