簡體   English   中英

從 eXist-db RestXQ 調用返回 zip 文件

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

我正在從 eXist-db 創建幾個 XML 文檔的 zip 文件。 此方法創建 zip 文件,但不返回它。 我嘗試存儲存在,但 zip 文件格式不正確。 如何獲得返回 zip 文件的調用?

eXist-db 版本 6.1.0-SNAPSHOT。 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
};

更新:

我嘗試將以下內容添加到退貨中

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

但它現在告訴我 $zip 沒有設置。

更新 2:

as item()+失蹤了。 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)
};

我沒有用 restXQ 試過這個,但在 eXist-db 中我使用

response:stream-binary#3

將 stream 二進制內容發送給客戶端。

我找到了解決辦法。 我錯過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