Hi Erik,

Thank you for your response!  After I read your email, the first thing I
tried was to remove the CRLF before the first boundary.  I must admit I
didn't believe it would help, but it seems it was the problem.  Removing it
made the request pass, in both the example I posted (ran in QConsole) and
in a totally separate example written for Node.

So to the REST API devs...  I am not an expert in the HTTP grammar (like if
if anyone could claim so), but it looks to me the CRLF should be ignored as
part of the preamble.  In any case, the 500 could be avoided (either to
ignore the CRLF or to return a 400 instead with a meaningful message).

But as far as I am concerned, problem solved ;-)  Thank you, Erik!

Regards,

-- 
Florent Georges
H2O Consulting
http://h2o.consulting/


On 30 July 2017 at 16:09, Erik Hennum wrote:

> Hi, Florent:
>
> I'm wondering whether a CRLF is required before the initial boundary.
> That seems to be implied but not explicitly stated by:
>
>     https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
>
> A couple of suggestions for investigating:
>
> *  Confirm that the constructed multipart/mixed is parseable using
> xdmp.multipartDecode()
>
>     https://docs.marklogic.com/xdmp.multipartDecode
>
> *  Write the two documents individually, read both document back in a
> single request that accepts multipart/mixed, and compare the REST API
> response to the constructed multipart/mixed
>
>     https://docs.marklogic.com/REST/GET/v1/documents
>
> If that doesn't discover the issue, maybe setting the content-length in
> the part might help (though the standard explicitly requires no headers in
> the part).
>
>
> Hoping that's useful,
>
>
> Erik Hennum
>
>
> ------------------------------
> *From:* general-boun...@developer.marklogic.com [
> general-boun...@developer.marklogic.com] on behalf of Florent Georges [
> li...@fgeorges.org]
> *Sent:* Sunday, July 30, 2017 5:56 AM
> *To:* MarkLogic Developer Discussion
> *Subject:* Re: [MarkLogic Dev General] Client API - 8000 - POST
> /v1/documents - Unexpected 400
>
> Hi,
>
> Actually, I made a mistake in the Content-Type of the overall request, I
> used "multipart/related" instead of "multipart/mixed" as mentioned in the
> doc.  But when I fix it, I get a 500 with the following error message:
>
> XDMP-AS: (err:XPTY0004) $meta-type as xs:string -- Invalid coercion: () as
> xs:string . See the MarkLogic server error log for further detail.
>
> It seems it all goes down to $content-type being the empty sequence in the
> following call in document-model-update.xqy (in ML 9.0-1.1):
>
> let $document-next   :=
>     if ($part-type ne "document-metadata") then ()
>     else docmodupd:parse-metadata-map($curr-uri,$content-type,$body)
>
> But then, it is beyond my knowledge...
>
> Regards,
>
> --
> Florent Georges
> H2O Consulting
> http://h2o.consulting/
>
>
> On 30 July 2017 at 11:41, Florent Georges wrote:
>
>> Hi,
>>
>> I am trying to use the POST /v1/documents endpoint on 8000 to insert
>> several documents at once.  From the chapter "Reading and Writing Multiple
>> Documents" in the REST Guide, in section "Specifying an Explicit Document
>> URI" [1], the following pseudo header in each part should be enough to set
>> the URI for each document:
>>
>> Content-Disposition: attachment;filename=/your/uri
>>
>> But I get a 400 with the message: "REST-REQUIREDPARAM: (err:FOER0000)
>> Required parameter: missing required extension parameter".
>>
>> Any idea why?
>>
>> [1]https://docs.marklogic.com/guide/rest-dev/bulk#id_84006
>>
>> Below a complete repro that can be played in QConsole (and later an
>> example using PUT instead, which does work):
>>
>> 'use strict';
>>
>> const rn  = '\r\n';
>> const bnd = '.ml.rockzzz.';
>> var body = rn;
>>
>> // first part
>> body += '--' + bnd + rn;
>> body += 'Content-Type: application/json' + rn;
>> body += 'Content-Disposition: attachment; filename="/test/multi-one.json"'
>> + rn;
>> body += rn;
>> body += JSON.stringify({ hello: 'one!' });
>> body += rn;
>>
>> // second part
>> body += '--' + bnd + rn;
>> body += 'Content-Type: application/json' + rn;
>> body += 'Content-Disposition: attachment; filename="/test/multi-two.json"'
>> + rn;
>> body += rn;
>> body += JSON.stringify({ hello: 'two!' });
>> body += rn;
>>
>> // after the last part
>> body += '--' + bnd + '--' + rn;
>>
>> xdmp.httpPost(
>>   'http://localhost:8000/v1/documents', {
>>     authentication : {
>>       method : 'digest',
>>       username : 'admin',
>>       password : 'admin'
>>     },
>>     headers: {
>>       "Content-type": 'multipart/related; boundary=' + bnd,
>>       Accept: "application/json"
>>     },
>>     data: body
>>   });
>>
>> Here is the example using PUT, and indeed working fine:
>>
>> 'use strict';
>>
>> xdmp.httpPut(
>>   'http://localhost:8000/v1/documents?uri=/test/single.json', {
>>     authentication : {
>>       method : 'digest',
>>       username : 'admin',
>>       password : 'admin'
>>     },
>>     headers: {
>>       "Content-type": 'application/json',
>>       Accept: "application/json"
>>     },
>>     data: JSON.stringify({ hello: 'world!' })
>>   });
>>
>> Any idea what I did wrong?
>>
>> Regards,
>>
>> --
>> Florent Georges
>> H2O Consulting
>> http://h2o.consulting/
>>
>>
>>
>
>
>
>
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to