Hello folks,

I have replicated the HTML form from this page http://en.wikibooks.org/wiki/XQuery/Uploading_Files

I am wondering if there are any suggestions on handling the upload efficiently.

I have modified the example to utilize the eXist templating.

The following example is good for smaller XSDs, but I am figuring that I may end up with some issues with a 300MB file.

The HTML file is:


<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
    <div class="row">
        <div data-template="app:foo-versions">
            <div class="col-md-2">
                <table class="table">
                    <tr data-template="templates:each" data-template-from="result" data-template-to="item">
                        <td>
                            <span data-template="app:foo-version-item"/>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="col-md-10">
                <div class="page-header">
                    <h1 data-template="config:app-title">Generated page</h1>
                </div>
                <div class="row">
                    <form enctype="multipart/form-data" method="post" action="upload.xq">
                        <div class="form-group">
                            <label>Subject Areas</label>
                            <div data-template="app:subject-areas"/>
                        </div>
                        <div class="form-group">
                            <label>Upload Document:</label>
                            <input type="file" name="file"/>
                        </div>
                        <div class="form-group">
                            <input type="submit" value="Upload"/>
                        </div>
                    </form>
                </div>
                <div class="row">
                    <div data-template="app:validate-list"/>
                </div>
            </div>
        </div>
    </div>
</div>

Here is the upload.xq that is called.

xquery version "3.0";

import module namespace config="http://fubar.org/apps/foo/config" at "modules/config.xqm";

let $filename := session:set-attribute('filename', request:get-uploaded-file-name('file'))
let $binary-filedata := request:get-uploaded-file-data('file')
let $content-string := util:binary-to-string($binary-filedata)
let $xsd := util:parse($content-string)//xs:schema

let $filedata := session:set-attribute('filedata', $xsd)
let $sa := session:set-attribute('subject-area', request:get-parameter('sa', ''))
let $r := response:redirect-to(xs:anyURI('validate.html')) 
return
<results>
   <message>File {$filename} has been stored in session.</message>
</results>