Changes

Jump to navigation Jump to search
604 bytes removed ,  20:49, 3 August 2013
{{Mark|Introduced with Version 7.7:}}
By Files can be uploaded to the server by using the content type {{Code|multipart/form-data}}, uploaded files can be handled server-side using RestXQ. A standard file upload input element can be used to upload files. Suppose you have a simple form (the HTML5 {{Code|multiple}} attribute enables the upload of multiple files):
<pre class="brush:xml">
<form name="myForm" action="/upload" method="POST" enctype="multipart/form-data">
Your Name: <input type="text" name="user-name"/><br/>
<input type="file" name="files[]" multiple="multiple" />
</form>
</pre>
In XQuery, the names and values of the {{Code|input}} elements will be represented as Uploaded files are stored in a [[Map module|map]]. Uploaded files (i. e., inputs of type {{Code|file}}) result in a : the filename serves as key and the file content, which is why the stored as value of file inputs will thus be represented in an additional map. The following example stores all shows how uploaded files can be stored in a temporary directory and returns XML elements for all inputs:
<pre class="brush:xquery">
declare
%rest:POST("{$data}")
%rest:path("/upload")
%rest:form-param("files", "{$files}") function local:upload($datafiles)
{
for $key in map:keys($data) let $value := $data($key) return if($val instance of map(*)) then ( (: handles uploaded files :) for $name in map:keys($valuefiles) let $content := $files($name) let $size path := count(convertfile:binarytemp-to-bytesdir() || $content))name return ( file:write-binary(file:temp-dir() || $namepath, $content), <file name="{ $name }" size="{ $file:size }"/> ) ) else ( (: other inputs :$path) <input name="{ $key }" value="{ $value }"/>
)
};
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu