Changes

Jump to navigation Jump to search
236 bytes added ,  18:47, 31 July 2013
</pre>
=File UploadUploads=
{{Mark|Introduced with Version 7.7:}}
By using the content type {{Code|multipart/form-data}} , uploaded files can be handled at server-side using RestXQ. A user is therefore able to upload files using a standard file upload input elementcan be used to upload files. Suppose you have a simple form(the HTML5 {{Code|multiple}} attribute enables the upload of multiple files):
<preclass="brush:xml">
<form name="myForm" action="/upload" method="POST" enctype="multipart/form-data">
<input type="hidden" name="example1test-key" value="test-value" /> <input type="file" name="files[]" multiple="multiple" />
</form>
</pre>
All In XQuery, the names and values of the {{Code|input }} elements will be put into represented as a [[#Map module|map]] using the element name as key. File elements will be treated differentlyUploaded files (i. e., as multiple files can be uploaded at once using the inputs of type {{Code|multiplefile}} attribute. All files will be put into ) result in a map using filename and the file name as key and this map content, which is accessible using {{Code|files}} as key why the value of the original file inputs will thus be represented in an additional map. See the The following example to store stores all uploaded files into in a specific temporary directory and reports the size and the name of the filefiles:
<pre class="brush:xquery">
declare
%restxqrest:POST("{$data}") %restxqrest:path("/upload") function pagelocal:upload($data)
{
for $key in map:keys($data) let $example1 val := $data('example1'$key) return if($val instance of map(*)) then ( (: handles uploaded files :) let $files := $data('files'$key) for $name in map:keys($files) let $content := $files($name) let $size := count(convert:binary-to-bytes($content)) return ( file:write-binary("files/"file:temp-dir() || $name, $content), <file name="{ $name }" size="{$size}"/> ) ) else ( (: handles remaining inputs :) <input name="{$namekey }" value="{ $val }<"/file>
)
};
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu