我可以插入EDUPUB(像Zip文件)在marklogic数据库通过Rest API扩展模块



用户将从UI上传EDUPUB/Zip文件。我们希望实现一个REST api扩展模块,以获取EDUPUB/Zip文件并将其摄取到MarkLogic数据库中。MarkLogic API API支持这个吗?有什么建议吗?

我实现了下面的代码来提取和上传一个EDUPUB/Zip文件

xquery version "1.0-ml";
declare namespace zip="xdmp:zip";
declare function local:epubupload ($filepath as xs:string)
{
let $get_document :=xdmp:document-get($filepath)
let $get_uri := fn:document-uri($get_document)
let $get_document_uri := fn:concat($get_uri, "/")
let $get_collection := fn:tokenize($get_uri, "\")[last()]
let $epub_extract := xdmp:zip-manifest($get_document)
for $each_file in $epub_extract/zip:part/text()
let $document_data := xdmp:zip-get($get_document, $each_file)
let $full_document_uri := fn:concat($get_document_uri, $each_file)
return xdmp:document-insert($full_document_uri, $document_data, (),    $get_collection)
};
local:epubupload("c:datasample.epub")

但是对于REST api,参数是什么?如何从用户系统中获取整个文件?

如果您正在创建自己的REST扩展,那么您可以在zip有效负载上使用以下模式:

1使用xdmp遍历zip文件:zip-manifest
对于每个条目,使用xdmp:zip-get提取文件
3通过xdmp:document-insert

保存到MarkLogic中

根据您发布内容的方式,xdmp:base64-decode可能是实际获取zip文件的代码的一部分。

最新更新