Changes

Jump to navigation Jump to search
6 bytes added ,  20:50, 3 August 2013
no edit summary
<pre class="brush:xquery">
%rest:form-param("parameter", "{$value}", "default")
</pre>
 
====File Uploads====
 
{{Mark|Introduced with Version 7.7:}}
 
Files can be uploaded to the server by using the content type {{Code|multipart/form-data}} (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">
<input type="file" name="files[]" multiple="multiple" />
</form>
</pre>
 
Uploaded files are stored in a [[Map module|map]]: the filename serves as key and the file content is stored as value. The following example shows how uploaded files can be stored in a temporary directory:
 
<pre class="brush:xquery">
declare
%rest:POST
%rest:path("/upload")
%rest:form-param("files", "{$files}")
function local:upload($files)
{
for $name in map:keys($files)
let $content := $files($name)
let $path := file:temp-dir() || $name
return (
file:write-binary($path, $content),
<file name="{ $name }" size="{ file:size($path) }"/>
)
};
</pre>
<body>done</body>
</html>
};
</pre>
 
=File Uploads=
 
{{Mark|Introduced with Version 7.7:}}
 
Files can be uploaded to the server by using the content type {{Code|multipart/form-data}} (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">
<input type="file" name="files[]" multiple="multiple" />
</form>
</pre>
 
Uploaded files are stored in a [[Map module|map]]: the filename serves as key and the file content is stored as value. The following example shows how uploaded files can be stored in a temporary directory:
 
<pre class="brush:xquery">
declare
%rest:POST
%rest:path("/upload")
%rest:form-param("files", "{$files}")
function local:upload($files)
{
for $name in map:keys($files)
let $content := $files($name)
let $path := file:temp-dir() || $name
return (
file:write-binary($path, $content),
<file name="{ $name }" size="{ file:size($path) }"/>
)
};
</pre>
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu