How to upload file in Alfresco?

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

How to upload file in Alfresco?

How to upload file in Alfresco via API?

Currently I am using  'cmis_repository_wrapper' class (please see attachment ) but not able to find related API for file upload?

Could you please guide me where I can get Alfresco API for file upload in PHP?

It would be good if you can share any example with it.

Thanks,

Sunil

9 Replies
ranjeetsi
Established Member II

Re: How to upload file in Alfresco?

Hi Sunil,

You can use the below github url for You can find a reference implementation in PHP using CMIS api

https://github.com/donbalon4/API_Alfresco

Alfresco Content Services Certified Engineer (ACSCE)
rspl
Member II

Re: How to upload file in Alfresco?

Hi Ranjeet,

Thanks for your reply. I have looked into given GIT repo and found that it is using 'uploadFile' function but not able to get where I can give destination path (Workspace path). 

I need to upload file into Alfresco workspace (in particular folder) . Just like we are uploading file into Alfresco after logged in into the Alfresco sysytem. Same thing I need to do via API so I don't need to login in to Alfresco server.

Please let me know that if you have any question. Could you please reply on this question asap. 

ranjeetsi
Established Member II

Re: How to upload file in Alfresco?

I have not tried using  "cmis_repository_wrapper" but have generated a fresh code without that - check below

php_upload.docx 

https://community.alfresco.com/servlet/JiveServlet/downloadBody/7997-102-1-14122/php_upload.docx 

=================================

PHP HttpRequest:

 

<?php

 

$request = new HttpRequest();

$request->setUrl('http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root');

$request->setMethod(HTTP_METH_POST);

 

$request->setQueryData(array(

  'objectId' => 'd140f140-2701-4ca6-8a80-8cdc9cd3b72c',

  'cmisaction' => 'createDocument',

  'propertyId[0]' => 'cmis:name',

  'propertyValue[0]' => 'ThirdPartyFormApigee.jpg',

  'propertyId[1]' => 'cmisSmiley SurprisedbjectTypeId',

  'propertyValue[1]' => 'cmis:document',

  'alf_ticket' => 'TICKET_3375c54fb50e6251d9e57f696483708ff9cc653a'

));

 

$request->setHeaders(array(

   'cache-control' => 'no-cache',

  'content-type' => 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'

));

 

$request->setBody('------WebKitFormBoundary7MA4YWxkTrZu0gW

Content-Disposition: form-data; name=""; filename="Penguins.jpg"

Content-Type: image/jpeg

 

 

------WebKitFormBoundary7MA4YWxkTrZu0gW--');

 

try {

  $response = $request->send();

 

  echo $response->getBody();

} catch (HttpException $ex) {

  echo $ex;

}

============================

Please let me know if it helps.

Alfresco Content Services Certified Engineer (ACSCE)
ranjeetsi
Established Member II

Re: How to upload file in Alfresco?

Also check for the url

http://cgit.drupalcode.org/cmis/tree/cmis_common/lib/cmis_repository_wrapper.php?id=6318766b3126da46... 

postObject method

Alfresco Content Services Certified Engineer (ACSCE)
rspl
Member II

Re: How to upload file in Alfresco?

Hi Ranjeet,

Thank You so much for your reply.

I have looked and tried your PHP CURL code but it is not giving me proper uploading functionality as i want.

With your code i am able to just create a new blank file on alfresco rather than uploading proper file from local.

I am attaching a screenshot of files which are creating on server with the help of your code.

Here you can see that it is creating blank image files with same name as of file which i want to upload.

can you please help me out here ??

ranjeetsi
Established Member II

Re: How to upload file in Alfresco?

Hi Sunil,

For this part of the code you will have to pass the content stream 

$request->setBody('------WebKitFormBoundary7MA4YWxkTrZu0gW

Content-Disposition: form-data; name=""; filename="Penguins.jpg"

Content-Type: image/jpeg

 

 

------WebKitFormBoundary7MA4YWxkTrZu0gW--');

On your system - it is not able to get content of the jpg file.

You have to set the body with content stream by getting the stream from the file. This is case of createDocument

The above way is independent of chemistry api and uses open http call

Please try and let me know if any questions. You may refer as below:

Other way you are trying is importing the wrapper: and creating from source.

How to do file versioning when uploading files to Alfresco using CMIS PHP - Stack Overflow 


					
				
			
			
				
Alfresco Content Services Certified Engineer (ACSCE)
ranjeetsi
Established Member II

Re: How to upload file in Alfresco?

Refer this url also - 

php-cmis-client/CreateDocument.php at master · dkd/php-cmis-client · GitHub 

Alfresco Content Services Certified Engineer (ACSCE)
rspl
Member II

Re: How to upload file in Alfresco?

Thanks Ranjeet,

Actually I am not getting, why we are creating file instead of file upload? Is there any Alfresco API for upload file in particular folder? 

In creating file, issue will come and it is not required. We need to upload file.

Could you please provide best contact number/email so I can talk to you and complete this feature. 

Thanks,

Sunil

ranjeetsi
Established Member II

Re: How to upload file in Alfresco?

Hi Sunil,

Please refer the OASIS specification of what apis does it support:

http://docs.oasis-open.org/cmis/CMIS/v1.1/os/CMIS-v1.1-os.pdf 

Upload a file to any env typically means - 1)have the content stream or input stream of data and then 2)create a new document .

You take the filestream and then create a new document at destination system using that input stream.

The apis available in CMIS are 

a) create document

b)create document from source

Once i get time - will try to get complete code - but in meantime look on the below:

php-cmis-client/CreateDocument.php at master · dkd/php-cmis-client · GitHub 

Alfresco Content Services Certified Engineer (ACSCE)