On Jul 31, 2017 12:24 AM, "Erik Hennum" <[email protected]> wrote:
> Hi, Florent: > > The mime type mapping for the extension takes precedence over the content > type header. To put it the other way, the header is used only if the > extension is not mapped. > > The rationale is that the header is ephemeral but the mapping is > persistent. The REST API encourages the best practice of using extensions > that reflect the content type. When that best practice is not followed, > the document content has to be inspected to determine the content type, > reducing the manageability of a database. The recommendation is to use > extensions that are consistent with the content type. > > > Hoping that clarifies, > > > Erik Hennum > > ------------------------------ > *From:* [email protected] [ > [email protected]] on behalf of Florent Georges [ > [email protected]] > *Sent:* Sunday, July 30, 2017 10:00 AM > *To:* MarkLogic Developer Discussion > *Subject:* [MarkLogic Dev General] Client API - Multipart doc ingest - > Set each part type > > Hi, > > I am using the POST /v1/documents endpoint of the Client API on 8000, to > ingest several documents in one multipart request. The section > "Controlling Document Type" [1], in chapter "Reading and Writing Multiple > Documents" in the REST Guide, says: > > "You can create JSON, XML, Binary, and Text documents in a bulk write. The > MIME type of the part Content-Type header determines the database document > type." > > And indeed, if I create a multipart to create documents with the following > URI, with the following Content-Type, then it works fine (it creates four > documents, of type resp. text, XML, JSON and binary): > > - /test/file-text.xxx - text/plain > - /test/file-xml.xxx - application/xml > - /test/file-json.xxx - application/json > - /test/file-bin.xxx - application/octet-stream > > But if I replace the URI to use the extension ".xqy" instead of ".xxx" > (the latter not being in the MIME table), then it uses text for all of > them. Like if the "extension" of the URI was used and took precedence if > it is in the MIME table. > > I can provide code to reproduce the multipart invocation, but I think it > would be rather noise here. The code below is to retrieve the type of each > document created. > > Is it a documentation bug? Or a product bug? Or just something I did > wrong? > > Regards, > > [1]https://docs.marklogic.com/guide/rest-dev/bulk#id_75274 > > declare function local:doc-type($uri as xs:string) > { > let $root := fn:doc($uri)/node() > return > if ( $root instance of text() ) then 'text' > else if ( $root instance of element() ) then 'xml' > else if ( $root instance of object-node() ) then 'json' > else 'binary' > }; > > ('/test/file-text.xqy', > '/test/file-xml.xqy', > '/test/file-json.xqy', > '/test/file-bin.xqy', > '/test/file-text.xxx', > '/test/file-xml.xxx', > '/test/file-json.xxx', > '/test/file-bin.xxx') > ! (. || ' - ' || local:doc-type(.)) > > Result is: > > /test/file-text.xqy - text > /test/file-xml.xqy - text > /test/file-json.xqy - text > /test/file-bin.xqy - text > /test/file-text.xxx - text > /test/file-xml.xxx - xml > /test/file-json.xxx - json > /test/file-bin.xxx - binary > > -- > Florent Georges > H2O Consulting > http://h2o.consulting/ > > > > _______________________________________________ > General mailing list > [email protected] > Manage your subscription at: > http://developer.marklogic.com/mailman/listinfo/general > >
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
