MarkLogic 12 EA 1 Product Documentation
xdmp.getRequestField

xdmp.getRequestField(
   name as String,
   [default as String?]
) as Object?

Summary

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.getRequestField 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.

Example

xdmp.getRequestField("index")
=> "10"

Example

Consider a form.sjs JavaScript module with the following content:

xdmp.setResponseContentType("text/html");

'<html xmlns="http://www.w3.org/1999/xhtml"> \n \
    <body> \n \
    <form name="test" action="upload.sjs?uid=' +xdmp.random() +'" \n \
          method="post" enctype="multipart/form-data"> \n \
    <p><label>File to upload: \n \
    <input type="file" class="name" name="upload" size="50"/></label></p> \n \
    <p><input type="submit" value="Upload and Get Results"/></p> \n \
    </form> \n \
    </body> \n \
 </html> '


Then have an upload.sjs JavaScript module as follows:

const filename = xdmp.getRequestFieldFilename("upload");
const disposition = fn.concat('attachment; filename=", filename, "');
const x = xdmp.addResponseHeader("Content-Disposition", disposition);
const x= xdmp.setResponseContentType( xdmp.getRequestFieldContentType("upload"));
xdmp.getRequestField("upload");

Execute the form.sjs 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.documentInsert to do so.

Powered by MarkLogic Server | Terms of Use | Privacy Policy