cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload file in Alfresco?

rspl
Champ in-the-making
Champ in-the-making

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 9

ranjeetsi
Star Contributor
Star Contributor

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
Champ in-the-making
Champ in-the-making

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
Star Contributor
Star Contributor

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)

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)