<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: REST API download attachment in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328241#M15242</link>
    <description>&lt;P&gt;Hi olaf,
As explained in the &lt;A href="https://doc.nuxeo.com/display/NXDOC/Nuxeo+Automation+Commands#NuxeoAutomationCommands-Blob.Get"&gt;Nuxeo Automation Commands doc&lt;/A&gt;, the Blob.Get operation need documents as input and accept an XPath to a property.
The documents input are explained in the &lt;A href="https://doc.nuxeo.com/display/NXDOC/Command+Endpoint#CommandEndpoint-ExecutingOperations"&gt;Nuxeo Command Endpoint doc&lt;/A&gt;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;"&lt;CODE&gt;doc:/default-domain/workspaces/myworkspace&lt;/CODE&gt;" or "&lt;CODE&gt;doc:96bfb9cb-a13d-48a2-9bbd-9341fcf24801&lt;/CODE&gt;"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;"&lt;CODE&gt;docs:/default-domain/workspaces/myworkspace, 96bfb9cb-a13d-48a2-9bbd-9341fcf24801&lt;/CODE&gt;"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Although your XPath is correct with &lt;CODE&gt;files:files/1/file&lt;/CODE&gt;, what you can find with the JSON/XML export of your main document.&lt;/P&gt;
&lt;P&gt;Note that the current version of the PHP Automation Client creates as &lt;CODE&gt;tempstream&lt;/CODE&gt; file when using the &lt;CODE&gt;Blob.Get&lt;/CODE&gt; operation (a rewrite of the client is under way), you can find an example in the &lt;A href="https://github.com/nuxeo/nuxeo-automation-php-client/blob/master/samples/B5.php"&gt;sample B5 in the sources of the client&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;With the previous data, you should be able to make a running code as the following :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-php"&gt;function GetBlob($path = '/default-domain/workspaces/Default Workspace/Some note') {
    $client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://nuxeo:8080/nuxeo/site/automation');
    $session = $client-&amp;gt;getSession('Administrator', 'Administrator');
    $answer = $session-&amp;gt;newRequest("Blob.Get")-&amp;gt;set('input', 'doc:' . $path)-&amp;gt;set('params', 'xpath', 'files:files/0/file')-&amp;gt;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');
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Sep 2016 10:44:06 GMT</pubDate>
    <dc:creator>Pierre-Gildas_M</dc:creator>
    <dc:date>2016-09-28T10:44:06Z</dc:date>
    <item>
      <title>REST API download attachment</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328238#M15239</link>
      <description>&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;With &lt;STRONG&gt;Blob.Get&lt;/STRONG&gt; 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):&lt;/P&gt;
&lt;P&gt;-&amp;gt;newRequest("Blob.Get")
-&amp;gt;set('input', 'doc:'' . $idoc)
-&amp;gt;set('input', 'docs:" . $idocs)
-&amp;gt;set('param', 'xpath', $xpath)&lt;/P&gt;
&lt;P&gt;docs and xpath are optional&lt;/P&gt;
&lt;P&gt;Depending on what you provide one can get returned:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;error 666 (not documented, but can be anything as it is the only error(number) which is implemented)&lt;/LI&gt;
&lt;LI&gt;some weird zip-file with the name+extension of the main document containing a structure of xml files&lt;/LI&gt;
&lt;LI&gt;the main document&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;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 ... ?&lt;/P&gt;
&lt;P&gt;Is this documented with examples somewhere?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 14:27:36 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328238#M15239</guid>
      <dc:creator>olaf_</dc:creator>
      <dc:date>2016-09-14T14:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: REST API download attachment</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328239#M15240</link>
      <description>&lt;P&gt;For the sake of completeness&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 15:36:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328239#M15240</guid>
      <dc:creator>olaf_</dc:creator>
      <dc:date>2016-09-14T15:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: REST API download attachment</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328240#M15241</link>
      <description>&lt;P&gt;Probably the closest thing to documentation on the subject is&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 14:54:32 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328240#M15241</guid>
      <dc:creator>olaf_</dc:creator>
      <dc:date>2016-09-20T14:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: REST API download attachment</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328241#M15242</link>
      <description>&lt;P&gt;Hi olaf,
As explained in the &lt;A href="https://doc.nuxeo.com/display/NXDOC/Nuxeo+Automation+Commands#NuxeoAutomationCommands-Blob.Get"&gt;Nuxeo Automation Commands doc&lt;/A&gt;, the Blob.Get operation need documents as input and accept an XPath to a property.
The documents input are explained in the &lt;A href="https://doc.nuxeo.com/display/NXDOC/Command+Endpoint#CommandEndpoint-ExecutingOperations"&gt;Nuxeo Command Endpoint doc&lt;/A&gt;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;"&lt;CODE&gt;doc:/default-domain/workspaces/myworkspace&lt;/CODE&gt;" or "&lt;CODE&gt;doc:96bfb9cb-a13d-48a2-9bbd-9341fcf24801&lt;/CODE&gt;"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;"&lt;CODE&gt;docs:/default-domain/workspaces/myworkspace, 96bfb9cb-a13d-48a2-9bbd-9341fcf24801&lt;/CODE&gt;"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Although your XPath is correct with &lt;CODE&gt;files:files/1/file&lt;/CODE&gt;, what you can find with the JSON/XML export of your main document.&lt;/P&gt;
&lt;P&gt;Note that the current version of the PHP Automation Client creates as &lt;CODE&gt;tempstream&lt;/CODE&gt; file when using the &lt;CODE&gt;Blob.Get&lt;/CODE&gt; operation (a rewrite of the client is under way), you can find an example in the &lt;A href="https://github.com/nuxeo/nuxeo-automation-php-client/blob/master/samples/B5.php"&gt;sample B5 in the sources of the client&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;With the previous data, you should be able to make a running code as the following :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-php"&gt;function GetBlob($path = '/default-domain/workspaces/Default Workspace/Some note') {
    $client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://nuxeo:8080/nuxeo/site/automation');
    $session = $client-&amp;gt;getSession('Administrator', 'Administrator');
    $answer = $session-&amp;gt;newRequest("Blob.Get")-&amp;gt;set('input', 'doc:' . $path)-&amp;gt;set('params', 'xpath', 'files:files/0/file')-&amp;gt;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');
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2016 10:44:06 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328241#M15242</guid>
      <dc:creator>Pierre-Gildas_M</dc:creator>
      <dc:date>2016-09-28T10:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: REST API download attachment</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328242#M15243</link>
      <description>&lt;P&gt;Thank you Pierre-Gildas Millon. When creating this new client could you please consider using http&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 15:11:29 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328242#M15243</guid>
      <dc:creator>olaf_</dc:creator>
      <dc:date>2016-09-30T15:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: REST API download attachment</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328243#M15244</link>
      <description>&lt;P&gt;The present version is an Automation API client, is does not implement the full Rest API of Nuxeo.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 12:29:10 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/rest-api-download-attachment/m-p/328243#M15244</guid>
      <dc:creator>Pierre-Gildas_M</dc:creator>
      <dc:date>2016-10-17T12:29:10Z</dc:date>
    </item>
  </channel>
</rss>

