简体   繁体   English

从 eXist-db RestXQ 调用返回 zip 文件

[英]Returning a zip file from an eXist-db RestXQ call

I am working on creating a zip file of several XML documents from eXist-db.我正在从 eXist-db 创建几个 XML 文档的 zip 文件。 This method creates the zip file, but does not return it.此方法创建 zip 文件,但不返回它。 I tried storing in exist, but the zip file is not the proper format.我尝试存储存在,但 zip 文件格式不正确。 How do I get the call to return the zip file?如何获得返回 zip 文件的调用?

eXist-db version 6.1.0-SNAPSHOT. eXist-db 版本 6.1.0-SNAPSHOT。 The latest pull of the JWT branch. JWT 分支最新拉取。

(:~

@param $jwt The JWT authorization token for RBAC
@param $host Tells the webserver which virtual host to use
@param $trim If true, then the empty properties in the JSON output are removed
@param $required A list of property names that are to remain during a trim even if they are empty
@return
@custom:openapi-tag Public
 :)
declare
    %rest:GET
    %rest:path("/v2/public/project/{$mapID}")
    %rest:header-param("JWT", "{$jwt}")
    %rest:header-param("Host", "{$host}")
    %rest:query-param("version", "{$version}", "latest")
    %rest:produces("application/octet-stream")
    %output:media-type("application/zip")
    %output:method("binary")
function v2pub:project-by-id(
            $jwt as xs:string*,
            $host as xs:string*,
            $mapID as xs:string*,
            $version as xs:string*
)
{
    let $login := login:authenticate($jwt)
    let $total-host := magutil:host($host)
    let $mapping := magutil:get-mapping-version($mapID, $version)
    let $mapping-entry := <entry name="" type="xml" method="store">{fn:serialize($mapping, map {"method": "xml" })}</entry>
    let $zip := compression:zip($mapping-entry, fn:false())
    return $zip
};

UPDATE:更新:

I tried adding the following to the return我尝试将以下内容添加到退货中

    return
<rest:response>
  <http:response status="200" message="Success">
    <http:header name="Content-Disposition" value="attachment; filename=test.zip"/>
  </http:response>
</rest:response>,
    $zip

But it is now telling me that $zip is not set.但它现在告诉我 $zip 没有设置。

UPDATE 2:更新 2:

I was missing as item()+ .as item()+失踪了。 The zip file is still not working though. zip 文件仍然无法正常工作。

xquery version "3.1";

module namespace v2pub = "http://easymetahub.com/modules/ns/public/v2";

declare namespace rest="http://exquery.org/ns/restxq";
declare namespace http = "http://expath.org/ns/http-client";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";

(:~

@param $jwt The JWT authorization token for RBAC
@param $host Tells the webserver which virtual host to use
@param $trim If true, then the empty properties in the JSON output are removed
@param $required A list of property names that are to remain during a trim even if they are empty
@return
@custom:openapi-tag Public
 :)
declare
    %rest:GET
    %rest:path("/v2/public/project/{$mapID}")
    %rest:header-param("JWT", "{$jwt}")
    %rest:header-param("Host", "{$host}")
    %rest:query-param("version", "{$version}", "latest")
    %rest:produces("application/octet-stream")
    %output:media-type("application/zip")
    %output:method("binary")
function v2pub:project-by-id(
            $jwt as xs:string*,
            $host as xs:string*,
            $mapID as xs:string*,
            $version as xs:string*
)
as item()+
{
    let $login := login:authenticate($jwt)
    let $total-host := magutil:host($host)
    let $mapping := magutil:get-mapping-version($mapID, $version)
    let $mapping-entry := <entry name="" type="xml" method="store">{fn:serialize($mapping, map {"method": "xml" })}</entry>
    let $zip := compression:zip($mapping-entry, fn:false())
    return
     (
<rest:response>
  <http:response status="200" message="Success">
    <http:header name="Content-Disposition" value="attachment; filename=test.zip"/>
  </http:response>
</rest:response>,
    $zip)
};

I have not tried this with restXQ but otherwise in eXist-db I use我没有用 restXQ 试过这个,但在 eXist-db 中我使用

response:stream-binary#3

to stream binary content to clients.将 stream 二进制内容发送给客户端。

I found the fix.我找到了解决办法。 I was missing as item()+我错过as item()+

xquery version "3.1";

module namespace v2pub = "http://easymetahub.com/modules/ns/public/v2";

declare namespace rest="http://exquery.org/ns/restxq";
declare namespace http = "http://expath.org/ns/http-client";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";

(:~

@param $jwt The JWT authorization token for RBAC
@param $host Tells the webserver which virtual host to use
@param $trim If true, then the empty properties in the JSON output are removed
@param $required A list of property names that are to remain during a trim even if they are empty
@return
@custom:openapi-tag Public
 :)
declare
    %rest:GET
    %rest:path("/v2/public/project/{$mapID}")
    %rest:header-param("JWT", "{$jwt}")
    %rest:header-param("Host", "{$host}")
    %rest:query-param("version", "{$version}", "latest")
    %rest:produces("application/octet-stream")
    %output:media-type("application/zip")
    %output:method("binary")
function v2pub:project-by-id(
            $jwt as xs:string*,
            $host as xs:string*,
            $mapID as xs:string*,
            $version as xs:string*
)
as item()+
{
    let $login := login:authenticate($jwt)
    let $total-host := magutil:host($host)
    let $mapping := magutil:get-mapping-version($mapID, $version)
    let $mapping-entry := <entry name="test.xml" type="xml" method="store">{fn:serialize($mapping, map {"method": "xml" })}</entry>
    let $zip := compression:zip($mapping-entry, fn:false())
    return
     (
<rest:response>
  <http:response status="200" message="Success">
    <http:header name="Content-Disposition" value="attachment; filename=test.zip"/>
  </http:response>
</rest:response>,
    $zip)
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM