1
votes

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') 
};
1
What user are you logged in as when running the eXide script vs. when you're calling the function from your app? Most likely the latter doesn't have write permissions on the target collection. To troubleshoot, try calling xmldb:login() with the user from the former from inside your app:upload_file() function. 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. - Joe Wicentowski
You were right, it was a permissions problem. Thanks for your support - Federico
Great! Then I'll add this info to an "answer" so that others who encounter a similar issue see it clearly labeled as the answer. If you could accept the answer, this will be even clearer. - Joe Wicentowski

1 Answers

2
votes

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.