0

我正在尝试创建一个单击按钮,该按钮允许将文件从存在数据库保存到本地磁盘。这是我现在拥有的:

<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 包含指向存在数据库中文件的链接:

<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>
4

1 回答 1

1

您必须从服务器中的查询中添加内容处置标头,并且 xf:load 将正常工作。

标题应如下所示:

Content-Disposition: attachment; filename="<result.xml>"

在 eXist-db XQuery 上获取它的方法是:

let $header := response:set-header('Content-Disposition',  'attachment; filename="result.xml"')
于 2016-07-05T17:28:20.893 回答