REST API download attachment
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?
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');
}
}
probably: ->set('param', 'xpath', 'files:files/1/file') But what about ->set('doc:'', '') ? Or must this be an ecm:path or …. ? Regardless what I add there I always seem to end up with error 666