<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.getRequestField.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.getRequestField</api:function-name><api:suggest>xdmp.getrequestfield</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>getrequestfield</api:suggest><api:function-link mode="xquery" fullname="xdmp:get-request-field">/apidoc/8.0/xdmp:get-request-field.xml</api:function-link><api:function mode="javascript" name="getRequestField" type="builtin" lib="xdmp" category="AppServerBuiltins" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.getRequestField"><api:summary>
  Returns the value of a named request field.  If the request field
  is a <code xmlns="http://www.w3.org/1999/xhtml">multipart/form-data</code> type in a POST form, you can
  use <code xmlns="http://www.w3.org/1999/xhtml">xdmp:get-request-field</code> for file upload applications
  (see the <a href="./xdmp.getRequestField#grf2js" class="javascript" xmlns="http://www.w3.org/1999/xhtml">second example</a> below).
</api:summary><api:params><api:param name="name" type="xs:string"><api:param-description>
    Request field name.
  </api:param-description><api:param-name>name</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="default" type="xs:string?" optional="true"><api:param-description>
    A default value to return if there is no request field.
  </api:param-description><api:param-name>default</api:param-name><api:param-type>String?</api:param-type></api:param></api:params><api:return class="javascript">Object?</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp.getRequestField("index")
=&gt; "10"
</pre></api:example><api:example class="javascript"><a id="grf2js" xmlns="http://www.w3.org/1999/xhtml"></a>
  <pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
Consider a form.sjs JavaScript module with the following content:

xdmp.setResponseContentType("text/html");

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


Then have an upload.sjs JavaScript module as follows:

var filename = xdmp.getRequestFieldFilename("upload");
var disposition = fn.concat('attachment; filename=", filename, "');
var x = xdmp.addResponseHeader("Content-Disposition", disposition);
var 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.

</pre></api:example></api:function></api:function-page>