MarkLogic Server 11.0 Product Documentation
xdmp:multipart-decode

xdmp:multipart-decode(
   $separator as xs:string,
   $data as binary(),
   [$options as xs:string*]
) as node()*

Summary

Extract the parts from a multipart encoding. The first item in the sequence is a manifest, and the remaining items are the decoded parts.

An attempt will be made to determine the type of content based on headers such as the part's content-type. If possible, an element will be returned, falling back to an xs:string, and finally binary().

The options control how the parts are unpacked. The supported option is "format=<value>" where value is one of xml, json, text, binary, or uri.

When set to xml, json, text, or binary, the specified format applies to all parts. Specifying binary will cause all parts to be returned as binary, and specifying text will cause all parts to be returned as xs:string if possible, falling back to binary() if necessary.

When set to uri, each part's type is determined individually: if the part has a Content-Type header, the format is determined from the Content-Type; otherwise, the filename from the Content-Disposition header is used to determine the format from the URI extension (using the same logic as xdmp:uri-format). This is useful when processing multipart requests where parts may not include Content-Type headers but do include Content-Disposition headers with filenames.

By default (when no options are specified), the format of each part is determined from its Content-Type header.

Parameters
separator The string that is to be used as a separator.
data The data (as a binary node) to be decoded.
options Decode options as strings. The supported option is "format=xml", "format=json", "format=text", "format=binary", or "format=uri".

Example

xquery version "1.0-ml";
let $html := document{ <html><p>Some stuff in an .html document</p></html> }
let $xml := document{ <root><a>Some other stuff in a .xml document</a></root> }
let $json := xdmp:to-json(("a",fn:false()))
let $boundary-string := "gc0p4Jq0M2Yt08jU534c0p"
let $mpe := xdmp:multipart-encode(
   $boundary-string,
   <manifest>
     <part>
       <headers>
         <Content-Type>application/xml</Content-Type>
         <boundary>gc0p4Jq0M2Yt08jU534c0p</boundary>
       </headers>
     </part>
     <part>
       <headers>
         <Content-Type>text/html</Content-Type>
       </headers>
      </part>
     <part>
       <headers>
         <Content-Type>application/json</Content-Type>
       </headers>
     </part>
   </manifest>,
   ($xml,$html,$json) )
return xdmp:multipart-decode($boundary-string, $mpe)
=>
<manifest>
  <part>
    <headers>
      <Content-Type>application/xml</Content-Type>
      <boundary>gc0p4Jq0M2Yt08jU534c0p</boundary>
      <Content-Length>94</Content-Length>
    </headers>
  </part>
  <part>
    <headers>
      <Content-Type>text/html</Content-Type>
      <Content-Length>90</Content-Length>
    </headers>
  </part>
  <part>
    <headers>
      <Content-Type>application/json</Content-Type>
      <Content-Length>12</Content-Length>
    </headers>
  </part>
</manifest>
<?xml version="1.0" encoding="UTF-8"?>
<root><a>Some other stuff in a .xml document</a></root>
<?xml version="1.0" encoding="UTF-8"?>
<html><p>Some stuff in an .html document</p></html>
["a", false]

Powered by MarkLogic Server | Terms of Use | Privacy Policy