1

我们有 rest 扩展,其中 post 方法的参数之一是我们想要处理的 zip,但我收到错误 500。以下消息显示在响应中。ZIP 由一些 json 和图像和 pdf 组成。是否有任何解决方法可以使其运行。

这是我在 PROD 环境中重现的情况:

扩展代码:

declare 
%roxy:params("")
%rapi:transaction-mode("update")
function dmc:post(
    $context as map:map,
    $params  as map:map,
    $input   as document-node()*
) as document-node()*
{
  let $_ := xdmp:log("**********")
  let $_ := xdmp:log($context)
  let $_ := xdmp:log("**********")

  let $_ := xdmp:log("**********")
  let $_ := xdmp:log($params)
  let $_ := xdmp:log("**********")

  let $_ := xdmp:log("**********")
  let $_ := xdmp:log($input)
  let $_ := xdmp:log("**********")

  let $_ := xdmp:log("**********")
  let $_ := xdmp:log(xdmp:get-request-field-content-type("rs:file"))
  let $_ := xdmp:log("**********")

  let $_ := map:put($context, "output-types", "application/xml")
  let $_ := map:put($context, "output-status", (201, "Created"))
  let $name := map:get($params, "name")
  let $file := map:get($params, "file")
  return document{c:my-function($name, $file)}
};

模块代码:

declare function c:my-function($name as xs:string, $file as binary()) as xs:string{

    let $my-name := $name
    let $my-file := $file
    return $my-name
};

错误日志:

2020-02-20 20:57:04.530 Info: **********
2020-02-20 20:57:04.530 Info: {"input-types":"multipart/form-data"}
2020-02-20 20:57:04.530 Info: **********
2020-02-20 20:57:04.530 Info: **********
2020-02-20 20:57:04.531 Info: {"file":["", "504b0304140000000800339fa94a56184dfee3850000209000001a00000000a882994a20b6abbe41000000410000000a00000000000000010020000000a38e0000617373656c2e6a736f6e504b05060000000003000300b90000000c8f00000000"], "name":"shrikant"}
2020-02-20 20:57:04.531 Info: **********
2020-02-20 20:57:04.531 Info: **********
2020-02-20 20:57:04.531 Info: **********
2020-02-20 20:57:04.531 Info: **********
2020-02-20 20:57:04.531 Info: application/x-zip-compressed
2020-02-20 20:57:04.531 Info: **********
2020-02-20 20:57:04.537 Notice: XDMP-AS: (err:XPTY0004) $file as binary() -- Invalid coercion: "" as binary()
2020-02-20 20:57:04.537 Notice:+in /config/config.xqy, at 21:60,
2020-02-20 20:57:04.537 Notice:+in xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/MyExtension","post"), "/marklogic.rest.resource/MyExtension/assets/resource.xqy")(map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...), document{binary{""}}) [1.0-ml]
2020-02-20 20:57:04.537 Notice:+in /MarkLogic/rest-api/lib/extensions-util.xqy, at 905:44,
2020-02-20 20:57:04.537 Notice:+in extut:call-service("MyExtension", "POST", xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/MyExtension","post"), "/marklogic.rest.resource/MyExtension/assets/resource.xqy"), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...), document{binary{""}}) [1.0-ml]
2020-02-20 20:57:04.537 Notice:+  $extension-name = "MyExtension"
2020-02-20 20:57:04.537 Notice:+  $method = "POST"
2020-02-20 20:57:04.537 Notice:+  $service = xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/MyExtension","post"), "/marklogic.rest.resource/MyExtension/assets/resource.xqy")
2020-02-20 20:57:04.537 Notice:+  $context = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>)
2020-02-20 20:57:04.537 Notice:+  $service-params = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...)
2020-02-20 20:57:04.537 Notice:+  $input = document{binary{""}}
2020-02-20 20:57:04.537 Notice:+in /MarkLogic/rest-api/lib/extensions-util.xqy, at 858:20,
2020-02-20 20:57:04.537 Notice:+in function() as item()*() [1.0-ml]
2020-02-20 20:57:04.537 Notice:+in /MarkLogic/rest-api/lib/extensions-util.xqy,
2020-02-20 20:57:04.537 Notice:+in xdmp:invoke(function() as item()*, <options xmlns="xdmp:eval"><isolation>different-transaction</isolation>...</options>) [1.0-ml]
2020-02-20 20:57:04.537 Notice:+in /MarkLogic/rest-api/lib/extensions-util.xqy, at 856:12,
2020-02-20 20:57:04.537 Notice:+in extut:invoke-service("MyExtension", "POST", "query", xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/MyExtension","post"), "/marklogic.rest.resource/MyExtension/assets/resource.xqy"), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...), document{binary{""}}, fn:false()) [1.0-ml]
2020-02-20 20:57:04.537 Notice:+  $extension-name = "MyExtension"
2020-02-20 20:57:04.537 Notice:+  $method = "POST"
2020-02-20 20:57:04.537 Notice:+  $default-txn-mode = "query"
2020-02-20 20:57:04.537 Notice:+  $service = xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/MyExtension","post"), "/marklogic.rest.resource/MyExtension/assets/resource.xqy")
2020-02-20 20:57:04.537 Notice:+  $context = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>)
2020-02-20 20:57:04.537 Notice:+  $service-params = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...)
2020-02-20 20:57:04.537 Notice:+  $input = document{binary{""}}
2020-02-20 20:57:04.537 Notice:+  $in-txn = fn:false()
2020-02-20 20:57:04.537 Notice:+  $txn-curr = "query"
2020-02-20 20:57:04.537 Notice:+  $txn-mode = "update"
2020-02-20 20:57:04.537 Notice:+in /MarkLogic/rest-api/models/resource-model-query.xqy, at 269:20,
2020-02-20 20:57:04.537 Notice:+in rsrcmodqry:resource-post("MyExtension", map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...), document{binary{""}}, fn:false(), local:rsrcmod-callback#6) [1.0-ml]
2020-02-20 20:57:04.537 Notice:+  $resource-name = "MyExtension"
2020-02-20 20:57:04.537 Notice:+  $context = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>)
2020-02-20 20:57:04.537 Notice:+  $resource-params = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...)
2020-02-20 20:57:04.537 Notice:+  $input = document{binary{""}}
2020-02-20 20:57:04.537 Notice:+  $in-txn = fn:false()
2020-02-20 20:57:04.537 Notice:+  $responder = local:rsrcmod-callback#6
2020-02-20 20:57:04.537 Notice:+  $service = xdmp:function(fn:QName("http://marklogic.com/rest-api/resource/MyExtension","post"), "/marklogic.rest.resource/MyExtension/assets/resource.xqy")
2020-02-20 20:57:04.537 Notice:+in /MarkLogic/rest-api/models/resource-model-query.xqy, at 236:4,
2020-02-20 20:57:04.537 Notice:+in rsrcmodqry:exec-post(map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>), map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...), document{binary{""}}, local:rsrcmod-callback#6) [1.0-ml]
2020-02-20 20:57:04.537 Notice:+  $headers = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>)
2020-02-20 20:57:04.537 Notice:+  $endpoint-params = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...)
2020-02-20 20:57:04.537 Notice:+  $input = document{binary{""}}
2020-02-20 20:57:04.537 Notice:+  $responder = local:rsrcmod-callback#6
2020-02-20 20:57:04.537 Notice:+in /MarkLogic/rest-api/endpoints/resource-service-query.xqy, at 78:8 [1.0-ml]
2020-02-20 20:57:04.537 Notice:+  $headers = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>)
2020-02-20 20:57:04.537 Notice:+  $method = "POST"
2020-02-20 20:57:04.537 Notice:+  $body = document{binary{""}}
2020-02-20 20:57:04.537 Notice:+  $params = map:map(<map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>...XDMP-CHILDNODEKIND: element nodes cannot have binary node children...)
2020-02-20 20:57:04.537 Notice:+  $extra-names = ()
2020-02-20 20:57:04.542 Info: Status 500: XDMP-AS: (err:XPTY0004) $file as binary() -- Invalid coercion: "" as binary()
4

1 回答 1

1

错误消息在这里非常清楚 - 例如,您不能有包含二进制内容的子节点,即不能将图像作为 XML 文档的子节点

这已经得到了更详细的回答:
Query generate 'XDMP-CHILDNODEKIND: $final -- element nodes cannot have binary node children' 错误

于 2020-02-20T07:03:53.693 回答