我正在尝试创建一个单击按钮,允许将文件从exists-db保存到本地磁盘。这就是我现在所拥有的:
<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包含指向exists-db:
中文件的链接<logLink>
{concat(request:get-scheme(), "://", request:get-server-name(),":", '8080', '/exist/rest/db/zips/Report4.7z')}
</logLink>
当我点击按钮浏览器尝试将其作为xml文件打开时,它会失败。我希望看到一个“保存文件”对话框。你能告诉我我在这里缺少什么吗?
我也尝试过提交 - 但没有成功。 提交:
<xf:submission id="loadLog" method="post">
<xf:resource value="concat({$xqueryPath},'serialize.xq')"/>
</xf:submission>
按钮:
<xf:trigger appearance="xxforms:download">
<xf:label>log link</xf:label>
<xf:action ev:event="DOMActivate">
<xf:send submission="loadLog"/>
</xf:action>
</xf:trigger>
查询:
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"), ())
当我自己运行serialize.xq时,我得到了这个:
<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>
答案 0 :(得分:1)
您必须在服务器中的查询中添加内容处置标头,xf:load才能正常工作。
标题应如下所示:
Content-Disposition: attachment; filename="<result.xml>"
在eXist-db XQuery上获取它的方法是:
let $header := response:set-header('Content-Disposition', 'attachment; filename="result.xml"')