Federico
Federico

Reputation: 47

Storing files with xquery in exist

Running the following xquery directly in eXide (Eval) it works fine, adding the XML files in MyFSdirectory into the MyCollectionPath:

xquery version "3.1";

let $selected_directory:= 'MyFSdirectory'
let $source-directory := $selected_directory
let $target-collection := 'MyCollectionPath'
return

    xmldb:store-files-from-pattern($target-collection, $source-directory, '*.xml')

But when I add it to a function and call it from my app, the store-files-from-pattern is not doing the job (no errors are shown but files are not uploaded), the check point is printed in my screen, so the function is being called correctly. Any hints?

    declare function app:upload_file($node as node(), $model as map(*)) {
    let $selected_directory:= "MyFSdirectory"
    let $source-directory := $selected_directory
    let $target-collection := "MyCollectionPath"
    return 
        <p>check point</p> |
        xmldb:store-files-from-pattern($target-collection, $source-directory, '*.xml') 
};

Upvotes: 1

Views: 186

Answers (1)

Joe Wicentowski
Joe Wicentowski

Reputation: 5294

This sounds like a permissions issue. In other words, when you run the script in eXide, you're likely running as a user (e.g., "admin") with write permissions on the target collection, but in your application the script is likely running as a guest user without the required permission to write to the target collection.

To troubleshoot, add an expression calling xmldb:login() to your app:upload_file() function, supplying the credentials for the user you use in eXide.

If elevating privileges this way works, then the next step would be to consider setting appropriate permissions on the target collection or setting applying setuid or setgid on the module that writes to the database.

Upvotes: 2

Related Questions