I want to add a document in a subdirectory

cancel
Showing results for 
Search instead for 
Did you mean: 
viperboys
Active Member II

I want to add a document in a subdirectory

Jump to solution

Hi

I want to add a document in a subdirectory. For example. 

I have a folder in -shared-/Test

I want to add a document inside the TEST folder

I would like something like that

http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-TEST-/children

Thank you

 

 

1 Solution

Accepted Solutions
EddieMay
Alfresco Employee

Re: I want to add a document in a subdirectory

Jump to solution

Hi @viperboys,

If you look at the api explorer - https://api-explorer.alfresco.com/api-explorer/#!/nodes/createNode - you will see in the notes about using the relativePath variable.

You can use the relativePath field to specify the folder structure to create relative to 
the node nodeId. Folders in the relativePath that do not exist are created before the
node is created.

The code in the payload my look a little like this:

{
  "name":"My Special Folder",
  "nodeType":"cm:folder",
  "relativePath":"X/Y/Z"
}

The API documentation says, "The relativePath specifies the folder structure to create relative to the node nodeId. Folders in the relativePath that do not exist are created before the node is created."

I've just tested uploading to a named folder using PHP. My code is as follows:

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://localhost/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-/children?alf_ticket=TICKET_1229b18962a93a9928878a7da424f19222f71df2",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => array('name' => 'Eddie May Upload',
'relativePath'=>'Shared/TEST',
'filedata'=> new CURLFILE('/Users/emay/Desktop/Test/TEST TWO.docx')), CURLOPT_HTTPHEADER => array( "Authorization: Basic dGVzdDp0ZXN0" ), )); $response = curl_exec($curl); curl_close($curl); echo $response;

The response was as follows:

{"entry":{"isFile":true,"createdByUser":{"id":"admin","displayName":"Administrator"},"modifiedAt":"2020-04-30T10:55:12.868+0000","nodeType":"cm:content",
"content":{"mimeType":"application/vnd.openxmlformats-officedocument.wordprocessingml.document","mimeTypeName":"Microsoft Word 2007","sizeInBytes":11760,"encoding":"UTF-8"},
"parentId":"9191350a-cadf-4afa-95c2-24203a8d9475","aspectNames":["cm:versionable","cm:titled","cm:auditable","cm:author"],"createdAt":"2020-04-30T10:55:08.176+0000","isFolder":false,
"modifiedByUser":{"id":"admin","displayName":"Administrator"},"name":"Eddie May Upload","id":"adc1d7b8-7381-467c-9278-c10bb5e29ccd","properties":{"cm:versionLabel":"1.0",
"cm:author":"Eddie May","cm:versionType":"MAJOR"}}}

You can see in the screenshot that the file was uploaded to the Shared/TEST folder off the repository root.

So, this code will send a file using PHP to a named folder within the Alfresco repository.

I'm not sure of your full requirement, but it looks like you will have to figure out which folders to upload to on the fly, perhaps using https://api-explorer.alfresco.com/api-explorer/#!/sites/listSiteContainers to find the folders within a site?

HTH,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!

View solution in original post

8 Replies
EddieMay
Alfresco Employee

Re: I want to add a document in a subdirectory

Jump to solution

Hi @viperboys ,

You can pass a relativePath value as part of your API call -

I've just used POSTMAN to test the following API call:

http://localhost:80/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-/children?alf_ticket=TICKET_579f7268c8de745562aa7e8d1920abf8ec1b382a 

I've set relativePath to "/Shared/Test"

As you'll see from the screenshot, I now have a document in the Shared/TEST folder.

HTH,

 

 

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
abhinavmishra14
Advanced

Re: I want to add a document in a subdirectory

Jump to solution

Look at this documentation: 

https://docs.alfresco.com/6.1/concepts/dev-api-by-language-alf-rest-upload-file.html

Hope this helps

[Edit] : @EddieMay  already responded.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
viperboys
Active Member II

Re: I want to add a document in a subdirectory

Jump to solution

Hi @EddieMay 

Thank you very much for you helping..

And how do I configure that relativePath ?? I don't see the TEST directory in the URL

Thank you

 

EddieMay
Alfresco Employee

Re: I want to add a document in a subdirectory

Jump to solution

Hi @viperboys ,

I manually created the directory within Share - logged in as Admin. Hence I knew the relativePath would be "/Shared/TEST".

HTH,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
viperboys
Active Member II

Re: I want to add a document in a subdirectory

Jump to solution

Hi @EddieMay 

I can't find that option you tell me. Can you send me a screenshot?

I don't know if I am doing it correctly. I'm looking at the Alfresco configuration but can't find it .. I want to send files to different folders in different site. For now I only do it to the root directory.

Thank you

EddieMay
Alfresco Employee

Re: I want to add a document in a subdirectory

Jump to solution

Hi @viperboys,

If you look at the api explorer - https://api-explorer.alfresco.com/api-explorer/#!/nodes/createNode - you will see in the notes about using the relativePath variable.

You can use the relativePath field to specify the folder structure to create relative to 
the node nodeId. Folders in the relativePath that do not exist are created before the
node is created.

The code in the payload my look a little like this:

{
  "name":"My Special Folder",
  "nodeType":"cm:folder",
  "relativePath":"X/Y/Z"
}

The API documentation says, "The relativePath specifies the folder structure to create relative to the node nodeId. Folders in the relativePath that do not exist are created before the node is created."

I've just tested uploading to a named folder using PHP. My code is as follows:

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://localhost/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-/children?alf_ticket=TICKET_1229b18962a93a9928878a7da424f19222f71df2",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => array('name' => 'Eddie May Upload',
'relativePath'=>'Shared/TEST',
'filedata'=> new CURLFILE('/Users/emay/Desktop/Test/TEST TWO.docx')), CURLOPT_HTTPHEADER => array( "Authorization: Basic dGVzdDp0ZXN0" ), )); $response = curl_exec($curl); curl_close($curl); echo $response;

The response was as follows:

{"entry":{"isFile":true,"createdByUser":{"id":"admin","displayName":"Administrator"},"modifiedAt":"2020-04-30T10:55:12.868+0000","nodeType":"cm:content",
"content":{"mimeType":"application/vnd.openxmlformats-officedocument.wordprocessingml.document","mimeTypeName":"Microsoft Word 2007","sizeInBytes":11760,"encoding":"UTF-8"},
"parentId":"9191350a-cadf-4afa-95c2-24203a8d9475","aspectNames":["cm:versionable","cm:titled","cm:auditable","cm:author"],"createdAt":"2020-04-30T10:55:08.176+0000","isFolder":false,
"modifiedByUser":{"id":"admin","displayName":"Administrator"},"name":"Eddie May Upload","id":"adc1d7b8-7381-467c-9278-c10bb5e29ccd","properties":{"cm:versionLabel":"1.0",
"cm:author":"Eddie May","cm:versionType":"MAJOR"}}}

You can see in the screenshot that the file was uploaded to the Shared/TEST folder off the repository root.

So, this code will send a file using PHP to a named folder within the Alfresco repository.

I'm not sure of your full requirement, but it looks like you will have to figure out which folders to upload to on the fly, perhaps using https://api-explorer.alfresco.com/api-explorer/#!/sites/listSiteContainers to find the folders within a site?

HTH,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
viperboys
Active Member II

Re: I want to add a document in a subdirectory

Jump to solution

Hi @EddieMay 

Thank you very much for you helping.. Now work fine for me. Smiley Very Happy 

Just to confirm, From this URL http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-/children.  Ca... I add for which site and which folder I send the file? For example:

CURLOPT_POSTFIELDS => array('name' => 'Eddie May Upload',
'site'=>'New site'
'relativePath'=>'Shared/TEST',
'filedata'=> new CURLFILE('/Users/emay/Desktop/Test/TEST TWO.docx')),

Thank you.

viperboys
Active Member II

Re: I want to add a document in a subdirectory

Jump to solution

Hi @abhinavmishra14 

Thank you for you helping.