Created
November 15, 2017 20:27
-
-
Save peterstadler/fd6ed3b082f0bc602597191fc9153e17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Something like this?
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($filename)
(: 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, request:get-uploaded-file-data($file), 'application/octet-stream')
(:let $store := xmldb:store($collection, $filename, request:get-uploaded-file-data('file')):)
I'm sure the syntax is incorrect--I figured I'd try to break something, but I am still receiving the "problem accessing form1.html" SAX exception. So I'm not sure the app:upload is even being run. I'll continue to play with it!
(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')):)
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
Ah, I think now I see: You are piping
request:get-uploaded-file-data("file")
directly toxmldb:store()
but the return type of the former isas xs:base64Binary*
and the latter expects it to be a "either a node, an xs:string, a Java file object or an xs:anyURI" (from the function documentation).So you have to pipe the result through
util:binary-to-string()
first!