phphttpalfrescoapache-chemistry

Download file from Alfresco through Chemistry in PHP


I'm currently having a problem downloading a file from Alfresco through Chemistry.

This is my code:

// Create the session
$repository = new CMISService($repositoryUrl, $userName, $password);
$uuid = $_GET['uuid'];
$contentData = $repository->getObject($uuid);
$tempurl = $repository->getLastRequestURL();

// TEMPORARY URL IS THIS: "http://193.43.168.90:8082/alfresco/api/-default-/public/cmis/versions/1.1/atom/id?id=6b82d8db-2003-467d-91e3-17a2d27f6a68";

$fp = fopen($tempurl, 'r');
$DMSContent = stream_get_contents($fp);
fclose($fp);

I'm not able to download the file because it returns me "HTTP request failed! HTTP/1.1 401 Unauthorized". It's like I'm not logged into Alfresco. How can I do this?


Solution

  • When working with Alfresco CMIS and Chemistry, I've had similar experiences, and have yet to get it to work. The following is a work around:

    Use the REST api download servlet specifically for fetching out files:

    https://wiki.alfresco.com/wiki/URL_Addressability#DownloadContentServlet

    You will need to get a ticket first:

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

    It will be returned between xml tags, you can easily parse it out and pass it to the download servlet as the alf_ticket parameter.

    Regards