marklogic api exension post binary

51 Views Asked by At

I wanted to create a REST service in XQuery who are able to receive zip file with documents. I try to use the API REST extension, but the input is a document-node and is unable to receive zip file. Is there a way to do that? I have to receive a very big number of files, and I want to zip them by 1000 documents to limit the network time. I use ml-gradle to create my database services


I do an other try : XQ :

declare function he.insertMedia:put(
$context as map:map,
$params as map:map,
$input as document-node()*
) as document-node()?
{  

    let $id := map:get($params,"id")
    let $uri := map:get($params,'uri')
    return ( xdmp:document-insert($uri,$input),
    document { <ok/> }
    )
};

CURL call :

curl --location --request PUT 'http://localhost:8175/LATEST/resources/he.insertMedia?rs:id=TestMarc&rs:uri=/test/testMarc' \
--header 'Content-type: application/xslt+xml' \
--data-binary '@/D:/Travail/3-1-ELS/cep-lss-octo-exampledata/DATA/ACTUEL_ARTICLE/media/000_1wy606.jpg'

Result :

{
    "errorResponse": {
        "statusCode": 400,
        "status": "Bad Request",
        "messageCode": "XDMP-DOCUTF8SEQ",
        "message": "XDMP-DOCUTF8SEQ: xdmp:get-request-body() -- Invalid UTF-8 escape sequence at  line 1 -- document is not UTF-8 encoded"
    }
}

ML version : 10.0-6.1

1

There are 1 best solutions below

0
Florent Georges On

You send binary but tells the server it is XML (XSLT as XML.) Try the following in cURL:

Content-Type: application/octet-stream