You can upload files from Forms using the content
type of multipart/form-data
.
The HTML5 attribute multiple
allows you upload multiple files in one go.
Consider the following HTML Form
<form action="/upload" method="POST" enctype="multipart/form-data">
<input type="file" name="files" multiple="multiple"/>
<input type="submit"/>
</form>
Files uploaded via a Form Parameter like this need to be routed
through to a MarkLogic map:map
object.
See the following example which could be use in conjunction
with the above HTML Form
declare
%rest:path("/upload")
%rest:form-param("files", "{$files}")
function upload($files as map:map) {
process($files)
};
content-type
and a body
content-type
is the Content Type of this particular filebody
is the Content Body of this particular file as a binary()
itemThe following example iterates through uploaded files,
getting each map:map
entry and then the
Content Type as well as the Body of that file.
declare
%rest:path("/upload")
%rest:form-param("files", "{$files}")
function example-upload($files as map:map) {
for $filename in map:keys($files) (: iterate through files :)
let $entry-map as map:map := map:get($files, $filename) (: a map per file :)
let $content-type as xs:string? := map:get($entry-map, "content-type")
let $body as binary() := map:get($entry-map, "body")
return ()
};