
xdmp:get-request-field( $name as xs:string, [$default as xs:string?] ) as item()*
Returns the value of a named request field. If the request field
is a multipart/form-data type in a POST form, you can use
xdmp:get-request-field
for file upload applications
(see the second
example below).
| Parameters | |
|---|---|
| name | Request field name. |
| default | A default value to return if there is no request field. |
xdmp:get-request-field("index")
=> "10"
Consider a form.xqy XQuery module with the following content:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form name="test" action="upload.xqy?uid={xdmp:random()}" method="post"
enctype="multipart/form-data">
<p><label>File to upload:
<input type="file" class="name" name="upload" size="50"/></label></p>
<p><input type="submit" value="Upload and Get Results"/></p>
</form>
</body>
</html>
Then have an upload.xqy XQuery module as follows:
let $filename := xdmp:get-request-field-filename("upload")
let $disposition := fn:concat("attachment; filename=""",$filename,"""")
let $x := xdmp:add-response-header("Content-Disposition", $disposition)
let $x:= xdmp:set-response-content-type(
xdmp:get-request-field-content-type("upload"))
return
xdmp:get-request-field("upload")
Execute the form.xqy file, select a file, and click the
"Upload and Get Results" button. The file you uploaded
will open according to the mime type the browser. If you
wanted to save it to the database, you could use
xdmp:document-insert to do so.
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.