Community articleAdding a file or set of files to a folder
Added by IBM contributorIBM on November 9, 2015
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars1 comment

Add a file or files to a folder programmatically.



Add a file or files to a folder programmatically.

You cannot add a file from your local directory to a folder; the file must already have been uploaded to the Files application. To add a file to a folder you must be an editor of the folder.

See Authenticating requests for information about how to authenticate the request.

Note: {collection-id} is the value of the <td:uuid> element in the Atom document of the folder to which you would like to add the files.

Input

You cannot add a file from your local directory to a folder; the file must already have been uploaded to the Files application. To add a file to a folder you must be an editor of the folder.

See Authenticating requests for information about how to authenticate the request.

Note: {collection-id} is the value of the <td:uuid> element in the Atom document of the folder to which you would like to add the files.

Input

Provide one of the following input types:

  • ItemID Atom entry document that defines the file that you want to add to the folder.
  • Files feed in which each entry identifies one of the files that you want to add to the folder.


Output

None

Authentication

This method requires authentication.

Input
Method URI Description
POST /files/basic/api/collection/{collection-id}/feed Adds a file or files that already exist in your library to the folder specified by the collection ID.
POST /files/{auth}/api/communitycollection/{community-id}/feed Add files to a community folder.
Content Type: text/plain
Name Type Optional Description
collection-id
string No {collection-id} is the value of the <td:uuid> element in the Atom document of the folder to which you would like to add the files.
Name Type Optional Description
itemId
string Yes String. Unique ID of the file that you want to add to the folder. You can find this value in the <td:uuid> element in the file's Atom document. You can specify this parameter more than once; separate each instance with an ampersand (&).
Note: Required if no input is provided with the request.
category
enumerated No String. Specifies the category of the file.
Default value is document.
Authorized values:
  • page
  • document
returnIsMultifiling
enumerated Yes String. Specify if return property "isMultifiling" of document after adding to the collection.
- If true, response will be 200 OK with property "isMultifiling" in document entry.
- If false, response will be same as other adding document action, 204 No Content.
Authorized values:
  • true
  • false
Output
Code Description
201
Indicates that the file or files were successfully added. If an error occurs, this header contains one of the error codes.
400
Bad Request.
401
Unauthorized.
403
Forbidden.
404
Not Found.
409
Conflict.
500
Internal server error. The server encountered an unexpected condition that prevented it from fulfilling the request.
References
Examples
POST /files/basic/api/collection/5b8d7bb9-6ce7-44d5-b4b2-2e9248970fb4/feed?returnContent=true&includeVisibleCollectionCount=true HTTP/1.1 

Response returned by the server
HTTP/1.1 200 OK

 
<feed xmlns:td="urn:ibm.com/td" xmlns="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:snx="http://www.ibm.com/xmlns/prod/sn" xmlns:thr="http://purl.org/syndication/thread/1.0">
   <generator version="0.0.0.0" uri="http://www.ibm.com/xmlns/prod/sn">IBM Connections - Files</generator>
   <id>urn:lsid:ibm.com:td:5b8d7bb9-6ce7-44d5-b4b2-2e9248970fb4</id>
   <link href="https://filesvm004.cn.ibm.com:9443/files/basic/api/collection/5b8d7bb9-6ce7-44d5-b4b2-2e9248970fb4/feed" rel="self"></link>
   <link href="https://filesvm004.cn.ibm.com:9443/files/basic/api/collection/5b8d7bb9-6ce7-44d5-b4b2-2e9248970fb4/entry" rel="edit"></link>
   <link href="https://filesvm004.cn.ibm.com:9443/files/app/folder/5b8d7bb9-6ce7-44d5-b4b2-2e9248970fb4/" rel="alternate"></link>
   <title type="text">testAddFile_collectionEndpoint_multifiling_personalCollection_private_1__1437121642141</title>
   <td:uuid xmlns:td="urn:ibm.com/td">5b8d7bb9-6ce7-44d5-b4b2-2e9248970fb4</td:uuid>
   <td:type xmlns:td="urn:ibm.com/td">personal</td:type>
   <subtitle type="text">testAddFile_collectionEndpoint_multifiling_personalCollection_private_1__1437121642141_Summary</subtitle>
   <author>
      <name>Liz Schonfeld</name>
      <snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">lschonfeld</snx:userid>
      <email>lschonfeld@renovations.com</email>
      <snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
   </author>
   <td:modifier xmlns:td="urn:ibm.com/td">
      <name>Liz Schonfeld</name>
      <snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">lschonfeld</snx:userid>
      <email>lschonfeld@renovations.com</email>
      <snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
   </td:modifier>
   <published>2015-07-17T08:27:29.469Z</published>
   <updated>2015-07-17T08:27:29.469Z</updated>
   <td:created xmlns:td="urn:ibm.com/td">2015-07-17T08:27:29.469Z</td:created>
   <td:modified xmlns:td="urn:ibm.com/td">2015-07-17T08:27:29.469Z</td:modified>
   <td:visibility xmlns:td="urn:ibm.com/td">private</td:visibility>
   <snx:isExternal xmlns:snx="http://www.ibm.com/xmlns/prod/sn">false</snx:isExternal>
   <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/item">1</snx:rank>
   <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/user">0</snx:rank>
   <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/group">0</snx:rank>
   <opensearch:totalResults xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">1</opensearch:totalResults>
   <td:allowSetFavorite xmlns:td="urn:ibm.com/td">true</td:allowSetFavorite>
   <td:allowFollowing xmlns:td="urn:ibm.com/td">true</td:allowFollowing>
   <entry>
      <id>urn:lsid:ibm.com:td:fd5f7b09-3175-4c1f-92a8-80a97439a180</id>
      <title type="text">testAddFile_collectionEndpoint_multifiling_personalDocument_private_1__1437121642144</title>
      <link href="https://filesvm004.cn.ibm.com:9443/files/basic/api/library/ff5eaa2d-c689-4f25-aba5-31e604e90a05/document/fd5f7b09-3175-4c1f-92a8-80a97439a180/entry" rel="self"></link>
      <link href="https://filesvm004.cn.ibm.com:9443/files/app/file/fd5f7b09-3175-4c1f-92a8-80a97439a180" rel="alternate" type="text/html"></link>
      <link href="https://filesvm004.cn.ibm.com:9443/files/basic/api/library/ff5eaa2d-c689-4f25-aba5-31e604e90a05/document/fd5f7b09-3175-4c1f-92a8-80a97439a180/entry" rel="edit"></link>
      <link href="https://filesvm004.cn.ibm.com:9443/files/basic/api/library/ff5eaa2d-c689-4f25-aba5-31e604e90a05/document/fd5f7b09-3175-4c1f-92a8-80a97439a180/media" rel="edit-media"></link>
      <link href="https://filesvm004.cn.ibm.com:9443/files/basic/anonymous/api/library/ff5eaa2d-c689-4f25-aba5-31e604e90a05/document/fd5f7b09-3175-4c1f-92a8-80a97439a180/media/testAddFile_collectionEndpoint_multifiling_personalDocument_private_1__1437121642144" rel="enclosure" type="text/plain" title="testAddFile_collectionEndpoint_multifiling_personalDocument_private_1__1437121642144" hreflang="en" length="84"></link>
      <link href="" rel="thumbnail"></link>
      <category term="document" scheme="tag:ibm.com,2006:td/type" label="document"></category>
      <link xmlns:thr="http://purl.org/syndication/thread/1.0" href="https://filesvm004.cn.ibm.com:9443/files/basic/api/library/ff5eaa2d-c689-4f25-aba5-31e604e90a05/document/fd5f7b09-3175-4c1f-92a8-80a97439a180/feed" rel="replies" type="application/atom+xml" thr:count="0"></link>
      <td:uuid xmlns:td="urn:ibm.com/td">fd5f7b09-3175-4c1f-92a8-80a97439a180</td:uuid>
      <td:added xmlns:td="urn:ibm.com/td">2015-07-17T08:27:29.469Z</td:added>
      <td:created xmlns:td="urn:ibm.com/td">2015-07-17T08:27:29.765Z</td:created>
      <published>2015-07-17T08:27:29.765Z</published>
      <updated>2015-07-17T08:27:29.859Z</updated>
      <td:modified xmlns:td="urn:ibm.com/td">2015-07-17T08:27:29.765Z</td:modified>
      <td:addedBy xmlns:td="urn:ibm.com/td">
         <name>Liz Schonfeld</name>
         <snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">lschonfeld</snx:userid>
         <email>lschonfeld@renovations.com</email>
         <snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
      </td:addedBy>
      <author>
         <name>Liz Schonfeld</name>
         <snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">lschonfeld</snx:userid>
         <email>lschonfeld@renovations.com</email>
         <snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
      </author>
      <td:modifier xmlns:td="urn:ibm.com/td">
         <name>Liz Schonfeld</name>
         <snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">lschonfeld</snx:userid>
         <email>lschonfeld@renovations.com</email>
         <snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
      </td:modifier>
      <td:label xmlns:td="urn:ibm.com/td">testAddFile_collectionEndpoint_multifiling_personalDocument_private_1__1437121642144</td:label>
      <td:libraryId xmlns:td="urn:ibm.com/td">ff5eaa2d-c689-4f25-aba5-31e604e90a05</td:libraryId>
      <td:libraryType xmlns:td="urn:ibm.com/td">personalFiles</td:libraryType>
      <td:versionUuid xmlns:td="urn:ibm.com/td">b261d033-e168-4c67-b532-3cb8c5254197</td:versionUuid>
      <td:versionLabel xmlns:td="urn:ibm.com/td">1</td:versionLabel>
      <summary type="text"></summary>
      <td:objectTypeName xmlns:td="urn:ibm.com/td">snx:file</td:objectTypeName>
      <td:propagation xmlns:td="urn:ibm.com/td">true</td:propagation>
      <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/recommendations">0</snx:rank>
      <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/comment">0</snx:rank>
      <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/hit">0</snx:rank>
      <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/anonymous_hit">0</snx:rank>
      <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/share">0</snx:rank>
      <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/collections">1</snx:rank>
      <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/attachments">0</snx:rank>
      <snx:rank xmlns:snx="http://www.ibm.com/xmlns/prod/sn" scheme="http://www.ibm.com/xmlns/prod/sn/versions">1</snx:rank>
      <td:totalMediaSize xmlns:td="urn:ibm.com/td">84</td:totalMediaSize>
      <td:visibility xmlns:td="urn:ibm.com/td">private</td:visibility>
      <content type="application/atom+xml" src="https://filesvm004.cn.ibm.com:9443/files/basic/api/library/ff5eaa2d-c689-4f25-aba5-31e604e90a05/document/fd5f7b09-3175-4c1f-92a8-80a97439a180/media"></content>
      <td:restrictedVisibility xmlns:td="urn:ibm.com/td">false</td:restrictedVisibility>
      <td:lock xmlns:td="urn:ibm.com/td" type="NONE"></td:lock>
      <snx:isExternal xmlns:snx="http://www.ibm.com/xmlns/prod/sn">false</snx:isExternal>
      <td:visibleCollectionCount xmlns:td="urn:ibm.com/td">1</td:visibleCollectionCount>
   </entry>
</feed>
Joe Wallace commented on Jul 12, 2016

Re: Adding a file or set of files to a folder

The example provided is for returning a feed and NOT an example of add a file to a folder.

Also it appears that a nonce header is REQUIRED, but is not mentioned in this topic.

Below are details of steps that I used to add an existing file to an existing folder.

** Used RESTClient

- Collect the folder uuid which will be used in URL as value for

- Collect the document uuid which will be used in URL as value for (itemid)

- Ensure that you are using "https" for URL

http:///files/basic/api/collection//feed?itemId= (http://%3Chostname%3E/files/basic/api/collection/%3Ccollectionid%3E/feed?itemId=%3Cdocumentid%3E)

- Retrieve nonce value from the server

https:///files/basic/api/nonce (https://%3Chostname%3E/files/basic/api/nonce)

- Add "Basic Auth" headder

- Add "X-Update-Nonce" header using nonce value that was return

- Run a POST request