Skip to content

Instantly share code, notes, and snippets.

@peterstadler
Created November 15, 2017 20:27
Show Gist options
  • Save peterstadler/fd6ed3b082f0bc602597191fc9153e17 to your computer and use it in GitHub Desktop.
Save peterstadler/fd6ed3b082f0bc602597191fc9153e17 to your computer and use it in GitHub Desktop.
xquery version "1.0";
declare function local:upload() {
let $filename := request:get-uploaded-file-name('file')
return
<results>
<message>File {$filename} has been stored.</message>
</results>
};
local:upload()
@peterstadler
Copy link
Author

(untested)

declare function app:upload($node as node(), $model as map(*)) {
   
let $collection := 'db/apps/NiC/inReview'
let $filename := request:get-uploaded-file-name('file')
let $file := util:binary-to-string(request:get-uploaded-file-data('file'))

(: make sure you use the right user permissions that has write access to this collection :)
let $login := xmldb:login($collection, 'username', 'superhardpassword')
let $store as xs:string? := xmldb:store($collection, $filename, $file)
(:let $store := xmldb:store($collection, $filename, request:get-uploaded-file-data('file')):) 

@tonyahowe
Copy link

Okay, so I got it to work--but in a very strange way. Do you have any insight? I think it's a controller/path issue, but why it works now and doesn't if I trust the controller to do what it's supposed to do is frustrating to no end: https://stackoverflow.com/questions/47182646/uploading-documents-to-a-server-using-xql-exist-db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment