cancel
Showing results for 
Search instead for 
Did you mean: 

REST API download attachment

olaf_
Champ on-the-rise
Champ on-the-rise

I know this question has been asked before and was even a subject of a blog article, but answers to those were focused on curl like URLs and not so much on input/output variables. So:

With Blob.Get one can get either the main-document or a document attached to a main-document depending on the parameters being passed. General layout would be (in PHP, but more or less generic):

->newRequest("Blob.Get") ->set('input', 'doc:'' . $idoc) ->set('input', 'docs:" . $idocs) ->set('param', 'xpath', $xpath)

docs and xpath are optional

Depending on what you provide one can get returned:

  • error 666 (not documented, but can be anything as it is the only error(number) which is implemented)
  • some weird zip-file with the name+extension of the main document containing a structure of xml files
  • the main document

So far I failed to get an attachment using the rest API. As the 'data' property contains the full URL it can be done using curl or the likes. But how to commence using the REST API itself (call returning a blob as can be expected of blob.get)? docs:utl from data? xpath:files:content[no-of-attachment] or ... ?

Is this documented with examples somewhere?

1 ACCEPTED ANSWER

Pierre-Gildas_M
Confirmed Champ
Confirmed Champ

Hi olaf, As explained in the Nuxeo Automation Commands doc, the Blob.Get operation need documents as input and accept an XPath to a property. The documents input are explained in the Nuxeo Command Endpoint doc:

"doc:/default-domain/workspaces/myworkspace" or "doc:96bfb9cb-a13d-48a2-9bbd-9341fcf24801"

"docs:/default-domain/workspaces/myworkspace, 96bfb9cb-a13d-48a2-9bbd-9341fcf24801"

Although your XPath is correct with files:files/1/file, what you can find with the JSON/XML export of your main document.

Note that the current version of the PHP Automation Client creates as tempstream file when using the Blob.Get operation (a rewrite of the client is under way), you can find an example in the sample B5 in the sources of the client.

With the previous data, you should be able to make a running code as the following :

function GetBlob($path = '/default-domain/workspaces/Default Workspace/Some note') {
    $client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://nuxeo:8080/nuxeo/site/automation');
    $session = $client->getSession('Administrator', 'Administrator');
    $answer = $session->newRequest("Blob.Get")->set('input', 'doc:' . $path)->set('params', 'xpath', 'files:files/0/file')->sendRequest();
    if (!isset($answer) OR $answer == false)
        echo '$answer is not set';
    else {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=image.png');
        readfile('tempstream');
    }
}

View answer in original post

5 REPLIES 5

olaf_
Champ on-the-rise
Champ on-the-rise

For the sake of completeness

olaf_
Champ on-the-rise
Champ on-the-rise

Probably the closest thing to documentation on the subject is

Pierre-Gildas_M
Confirmed Champ
Confirmed Champ

Hi olaf, As explained in the Nuxeo Automation Commands doc, the Blob.Get operation need documents as input and accept an XPath to a property. The documents input are explained in the Nuxeo Command Endpoint doc:

"doc:/default-domain/workspaces/myworkspace" or "doc:96bfb9cb-a13d-48a2-9bbd-9341fcf24801"

"docs:/default-domain/workspaces/myworkspace, 96bfb9cb-a13d-48a2-9bbd-9341fcf24801"

Although your XPath is correct with files:files/1/file, what you can find with the JSON/XML export of your main document.

Note that the current version of the PHP Automation Client creates as tempstream file when using the Blob.Get operation (a rewrite of the client is under way), you can find an example in the sample B5 in the sources of the client.

With the previous data, you should be able to make a running code as the following :

function GetBlob($path = '/default-domain/workspaces/Default Workspace/Some note') {
    $client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://nuxeo:8080/nuxeo/site/automation');
    $session = $client->getSession('Administrator', 'Administrator');
    $answer = $session->newRequest("Blob.Get")->set('input', 'doc:' . $path)->set('params', 'xpath', 'files:files/0/file')->sendRequest();
    if (!isset($answer) OR $answer == false)
        echo '$answer is not set';
    else {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=image.png');
        readfile('tempstream');
    }
}

Thank you Pierre-Gildas Millon. When creating this new client could you please consider using http

The present version is an Automation API client, is does not implement the full Rest API of Nuxeo.

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.