[英]How to zip binary files during function’s run in eXist-db and xQuery
[英]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.