简体   繁体   中英

How do I download an image from an Alfresco repository using CMIS?

I'm working with a system that uploads and downloads images on an Alfresco repository following the structure: " root/folder1/folder2/image.jpg "

I managed to fix the uploading part but I'm struggling trying to download the images, I have the following code:

if(!empty($path)) {
    $path = $this->_clientCMIS->getObjectByPath('/'.$path);
    $path = ' AND IN_FOLDER(\''.$path->id.'\')';
}
$query = 'SELECT * FROM cmis:document WHERE cmis:name = \''.$file.'\''.$path;
$documents = $this->_clientCMIS->query($query);
foreach ($documents->objectList as $document) {
   $data = explode(':', $document->uuid);
   array_push($response['data'], array(
      'id' => $document->properties['cmis:objectId']
      , 'path' => (isset($document->properties['cmis:path']))?$document->properties['cmis:path']:''
      , 'name' => $document->properties['cmis:name']
      , 'url' => 'http://'.$this->_ip.$this->_port.'/share/proxy/alfresco/api/node/content/workspace/SpacesStore/'.$data[2].'/'.$document->properties['cmis:name']
      , 'type' => 'file'
      , 'size' => $document->properties['cmis:contentStreamLength']
      , 'createdBy' => $document->properties['cmis:createdBy']
      , 'creationDate' => $document->properties['cmis:creationDate']
      , 'lastModifiedBy' => $document->properties['cmis:lastModifiedBy']
      , 'lastModificationDate' => $document->properties['cmis:lastModificationDate']
      , 'parentId' => (isset($document->properties['cmis:parentId']))?$document->properties['cmis:parentId']:''
   ));
}
$response['total'] = sizeof($response['data']);
$response['error'] = '';

I checked the $path and $file variables and their values are correct (the folder where the image is stored and the image's name) but the query returns an empty object list (therefore, the code never enters the foreach loop). The value of the $query variable is something like this:

SELECT * FROM cmis:document WHERE cmis:name = 'my_image.jpg' AND IN_FOLDER('workspace://SpacesStore/5acb1737-b30a-2ff8-d47a-7f360c235bd0')

That query should work. I suggest you use something like the Apache Chemistry OpenCMIS Workbench to test your query (or the node browser in Alfresco).

It could be that the user you are authenticated as does not have access to the folder you are querying against.

Also, a minor nit, but be careful about confusing an Alfresco node reference for a CMIS object ID. Those are not the same thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM