I am trying to create a button clicking on which allows to save a file from exist-db to local disk. Here is what I have now:
<xf:trigger appearance="xxforms:download" mediatype="application/octet-stream">
<xf:label>log link</xf:label>
<xf:action ev:event="DOMActivate">
<xf:load show="new">
<xf:resource value="logLink"/>
</xf:load>
</xf:action>
</xf:trigger>
logLink contains a link to the file in exist-db:
<logLink>
{concat(request:get-scheme(), "://", request:get-server-name(),":", '8080', '/exist/rest/db/zips/Report4.7z')}
</logLink>
When I click the button browser tries to open it as an xml file and it fails. I expected to see a Save File dialog. Could you tell me what I'm missing here?
I also tried to do it via submission - without success. Submission:
<xf:submission id="loadLog" method="post">
<xf:resource value="concat({$xqueryPath},'serialize.xq')"/>
</xf:submission>
Button:
<xf:trigger appearance="xxforms:download">
<xf:label>log link</xf:label>
<xf:action ev:event="DOMActivate">
<xf:send submission="loadLog"/>
</xf:action>
</xf:trigger>
Query:
let $filename := '/db/horner/zips/Report4.7z'
let $fileurl := 'http://localhost:8080/exist/rest/db/horner/zips/Report4.7z'
(:return file:serialize-binary(util:binary-doc($filename), 'C:\temp\test.7z'):)
return
httpclient:get($fileurl, xs:boolean("true"), ())
I get this when I run serialize.xq itself:
<httpclient:response xmlns:httpclient="http://exist-db.org/xquery/httpclient" statusCode="200">
<httpclient:headers>
<httpclient:header name="Date" value="Mon, 04 Jul 2016 14:24:48 GMT"/>
<httpclient:header name="Set-Cookie" value="JSESSIONID=4lvf1wiu5xgph311yol31zkq;Path=/exist"/>
<httpclient:header name="Expires" value="Thu, 01 Jan 1970 00:00:00 GMT"/>
<httpclient:header name="Last-Modified" value="Mon, 04 Jul 2016 09:30:44 GMT"/>
<httpclient:header name="Created" value="Mon, 04 Jul 2016 09:30:44 GMT"/>
<httpclient:header name="Content-Type" value="application/xml"/>
<httpclient:header name="Content-Length" value="2506"/>
<httpclient:header name="Server" value="Jetty(8.1.9.v20130131)"/>
</httpclient:headers>
<httpclient:body mimetype="application/xml" type="binary" encoding="Base64Encoded">N3q8ryccAASdSWz3SAkAAAAAAABiAA.... bla bal bla </httpclient:body>
</httpclient:response>
You have to add a content-disposition header from the query in the server, and the xf:load will work fine.
The header should look like:
The way of getting it on eXist-db XQuery is: