0

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

  • What issue are you running into? And what client are you using for testing? If you are correctly posting a binary, the document-node should be a binary that you can then pass into the appropriate XQuery zip function. – rjrudin Oct 22 '22 at 12:18
  • "I try to use the API REST extension, but the input is a document-node and is unable to receive zip file." - what do you mean? Can you provide a link to a resource that is giving you the impression that you can't POST the zip file? Or even better, some code demonstrating what your REST extension is and how you are attempting to send the zip to it, and/or any errors that you are getting? – Mads Hansen Oct 22 '22 at 21:13
  • I use postman or curl that's the declaration of my function declare function he.inputZipJobs:put($context as map:map, $params as map:map, $documents as document-node()) as document-node()? { that the error I receive { "errorResponse": { "statusCode": 500, "status": "Internal Server Error", "messageCode": "INTERNAL ERROR", "message": "XDMP-DOCXMLCHAR: xdmp:get-request-body() -- Invalid XML character codepoint 3 at line 1 -- document contains non-XML character . See the MarkLogic server error log for further detail." } } – Marc Messéant Oct 25 '22 at 12:05
  • I do an other try : XQ : – Marc Messéant Oct 27 '22 at 06:06
  • It looks like you are sending a binary (jpg) with a content type for xml. Try sending image/jpeg or whatever instead as the mime type. – asusu Nov 22 '22 at 20:37

1 Answers1

0

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

Content-Type: application/octet-stream
Florent Georges
  • 2,190
  • 1
  • 15
  • 24