How to create folder in Alfresco by RESTful API

2019-02-14 14:42发布

I am using Freshdocs for Android

I can login to the Alfresco server using this API call:

GET /alfresco/service/api/login?u={username}&pw={password?}

But how do I create a new folder in Alfresco?

标签: alfresco
3条回答
相关推荐>>
2楼-- · 2019-02-14 15:16

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

查看更多
你好瞎i
3楼-- · 2019-02-14 15:25

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/

查看更多
Ridiculous、
4楼-- · 2019-02-14 15:32

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.

查看更多
登录 后发表回答