This works, but the files will be stored with owner rights “root:staff” and not “:staff”.
Why is Servoy server using “root” instead of “”?
When I check by function if the file is stored:
var _path = plugins.file.getDefaultUploadLocation() + ‘/’ + attachment_real_name;
var _file = plugins.file.convertToJSFile(_path);
_file.exists() returns false
although the file exist in the upload location!?
Deleting the file also fails by
var _location = plugins.file.getDefaultUploadLocation(),
_name = attachment_real_name,
_filepath = _location + ‘/’ + _name;
_file = plugins.file.convertToJSFile(_filepath),
_success = plugins.file.deleteFile(_file);
Because of the owner rights “root” of the file, I can manually remove it only as sudo, but I can.
I would expect Servoy to write the file using the user running servoy server.
And then you should be able to read/check/work with that file from scripting running on server.
Are you by any chance using smart-client to try to read the file (which might be running it’s code in it’s web-start process on the client so it might be running under another user)?
What exactly do you need to do with that file?
If I understood correctly you are running both the app. server and the smart client on the same comp. That is why you can access that location from both places.
The use case is - you have a file on client. Then you upload it to application server (which is usually another machine). Then you can’t expect to be able to access that file you just streamed to the server from your client’s file system.
There are methods in the file plugin containing the word “remote” in them. You can try using one of those instead to work with the uploaded file.
I don’t have a server - client constellation on one machine. Only my Servoy Developer environment, but I know the difference because of the Servoy server and debug client are running on the same machine.
Now I think I understand why my function is working in the debug client but not in the smart client. The functions where handeled from the smart client with the rights of the client PC and not by the server, right?
What I want to do in the smart client is:
selecting a file in any direction on the network
storing/streaming it to the direction set in servoy-admin
checking/validating if the file exists in the direction
deleting/removing the file
I will try the “remote” methods of the file plugin.
You are welcome.
Yes, you are right. When running in developer, both the debug smart client and the ‘application server’ are running in the same process / same user. That is why it works there.
Do you use separate OS users for starting clients? Cause if you always use the same user for starting clients you could also make the server run under the same user .
Andrei Costescu:
Do you use separate OS users for starting clients? Cause if you always use the same user for starting clients you could also make the server run under the same user .
this is not an option.
I have tried the “remote” method of the file plugin
var _path = plugins.file.getDefaultUploadLocation();
var _dir = plugins.file.convertToJSFile(_path);
// _path == E:\Servoy\images
var _files = new Array();
_files = plugins.file.getRemoteFolderContents(_dir,'.jpg',1);
but I get the error message:
Wrapped java.lang.IllegalArgumentException: Local file path doesn't make sense for the getRemoteDirList method
I will create a case for enhancing the method docs for remote file usage.
When you work with remote files, the local client paths do not make any sense (they could be on different machines, have different access rights even if they run on the same machine and so on).
So when working with remote files, you either have to use JSFile instances that you get from a call to a ‘…remoteXYZ’ method or a string that has to start with ‘/’ and maps relative to the server default upload directory.
So if you have uploaded a file ‘a.jpg’ you should be able to access it through ‘/a.jpg’. Didn’t try it right now but this is the general idea.
So I would try this instead:
var _files = new Array();
_files = plugins.file.getRemoteFolderContents('/', '.jpg', 1);
This works, but the files will be stored with owner rights “root:staff” and not “:staff”.
Why is Servoy server using “root” instead of “”?
I’m being bitten by exactly the same issue. I have other scripts that need to work on the files stored on the server, and because they are not run as ‘root’ they fail…