
xdmp.multipartDecode( separator as String, data as binary(), [options as String[]] ) as Sequence
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.
var html = fn.head(xdmp.unquote(
'<html><p>Some stuff in an .html document</p></html>'));
var xml = fn.head(xdmp.unquote('<root> \n\
<a>Some other stuff in a .xml document</a> \n\
</root>'));
var json = xdmp.toJSON(["a",false]);
var boundaryString = "gc0p4Jq0M2Yt08jU534c0p";
var manifest = fn.head(xdmp.unquote(
'<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>')).root;
var mpe = xdmp.multipartEncode(
boundaryString,
manifest,
[xml,html,json] );
xdmp.multipartDecode(boundaryString, mpe);
=>
[
{
"headers": {
"Content-Type": "application/xml",
"boundary": "gc0p4Jq0M2Yt08jU534c0p",
"Content-Length": "148"
}
},
{
"headers": {
"Content-Type": "text/html",
"Content-Length": "90"
}
},
{
"headers": {
"Content-Type": "application/json",
"Content-Length": "12"
}
}
]
<?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]