How to create folder in Alfresco by RESTful API

柔情痞子 提交于 2019-11-30 22:39:34

There are two main options, but it'll depend on what else you want to do, and what version of Alfresco you're running.

Assuming you want to keep things very simple, and you just want to create one folder, and you're using Alfresco 4.1 or later, then you can use the org.alfresco.repository.node.folder.post webscript. For this, simply post JSON like either

 { "name": "NewNodeName" }

or

{  
   "name": "NewNodeName",
   "title": "New Node Title",
   "description": "A shiny new node",
   "type": "cm:folder"
}

To the API, which takes a URL like /api/site/folder/{site}/{container}/{path}

Alternately, if you want to do a number of different file and folder operations (eg navigate the folder structure, create a folder, upload a file to it etc), then you should instead use CMIS. Apache Chemistry is a great library to use for CMIS, and it even has an Android client! The docs for the android client are still being written thought (the Android port was only just added), so you might need to ask on the mailing list if you don't have time to wait for the docs.

To create a folder through api you can use the following queries:

a) To create defined type folder using full path to parent folder

       url: "/../alfresco/service/api/site/folder/" + siteName + "/documentLibrary/" + parentFolderPath
       method: "POST"
       json: {
           name: name
           type: folderType
       }

siteName - website name created in Alfresco;

parentFolderPath - path to parent folder;

name -folder name;

type - folder type.

Example:

     url: "/../alfresco/service/api/site/folder/example/documentLibrary/books"
       method: "POST"
       json: {
           name: "Pushkin"
           type: "cm:folder"
       }

After making the request "Pushkin" folder is created. This folder is situated in “books” folder of documents library on the "example" website.

b) To create folder by nodeRef

nodeRef is an object id in Alfresco. Each object has its own nodeRef. This request creates new object inside given object of folder type.

       xml = '<?xml version="1.0" encoding="utf-8"?>' + '<entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/"
    xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/">' +
           '<title>' + folderName + '</title>' +
           '<summary>' + folderName + '</summary>' +
           '<cmisra:object>' +
           '<cmis:properties>' +
           '<cmis:propertyId
    propertyDefinitionId="cmis:objectTypeId">' +
           '<cmis:value>' + folderType + '</cmis:value>' +
           '</cmis:propertyId>' +
           '</cmis:properties>' +
           '</cmisra:object>' +
           '</entry>';
       url: "/../alfresco/service/api/node/workspace/SpacesStore/" +
    nodeRef + "/children"
       method: "POST"
       headers: {
           "Content-Type": "application/atom+xml;type=entry"
       },
       xml: xml

folderName - folder name;

folderType - folder type;

nodeRef - folder id in Alfresco.

Example:

       nodeRef = b544cd67-e839-4c60-a616-9605fa2affb7;
       xml = '<?xml version="1.0" encoding="utf-8"?>' +
           '<entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/"
    xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/">' +
           '<title>Example of creating a folder</title>' +
           '<summary>Example of creating a folder</summary>' +
           '<cmisra:object>' +
           '<cmis:properties>' +
           '<cmis:propertyId propertyDefinitionId="cmis:objectTypeId">' +
           '<cmis:value>cm:folder</cmis:value>' +
           '</cmis:propertyId>' +
           '</cmis:properties>' +
           '</cmisra:object>' +
           '</entry>';
       url: "/../alfresco/service/api/node/workspace/SpacesStore/" + nodeRef + "/children"
       method: "POST"
       headers: {
           "Content-Type": "application/atom+xml;type=entry"
        },
       xml: xml

Other services and their description you can find here:

http://jazzteam.org/en/technical-articles/list-of-alfresco-services/

You should use POST /alfresco/service/api/path/{store_type}/{store_id}/{id}/children

Read the docs for detailed information:

http://wiki.alfresco.com/wiki/Repository_RESTful_API_Reference#Create_folder_or_document_.28createDocument.2C_createFolder.29

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!