Page 1 of 1

streamFilesToServer functionality

PostPosted: Tue Feb 16, 2016 11:42 am
by tgs
Hello,

in my solution I load and stream files by

"plugins.file.streamFilesToServer(_file,_new_name,m_streamingDone)"

to the

"servoy.FileServerService.defaultFolder:"

set in servoy-admin on a Mac OS X server.

This works, but the files will be stored with owner rights "root:staff" and not "<username>:staff".
Why is Servoy server using "root" instead of "<username>"?

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.

Servoy 7.4.6
Mac OS X 10.11 Server
Java 1.8_74

Regards Thomas

Re: streamFilesToServer functionality

PostPosted: Tue Mar 08, 2016 1:47 pm
by tgs
Any help and/or information would be appreciated.

Thomas

Re: streamFilesToServer functionality

PostPosted: Tue Mar 08, 2016 9:04 pm
by Andrei Costescu
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)?

Re: streamFilesToServer functionality

PostPosted: Tue Mar 08, 2016 9:42 pm
by tgs
Hi Andrei,

what do you mean with this:
Andrei Costescu wrote:Are you by any chance using smart-client to try to read the file ...

How should I "read" the file?

Re: streamFilesToServer functionality

PostPosted: Tue Mar 08, 2016 10:19 pm
by Andrei Costescu
I meant to ask if you are using smart client :).
Cause that can execute as another user. If you were running web/ng then the code would run server-side.

Re: streamFilesToServer functionality

PostPosted: Tue Mar 08, 2016 10:34 pm
by tgs
Ahh ok, sorry. I'm currently a little confused...

Yes, the solution is running only with smart clients!

Is there any solution for this?

Re: streamFilesToServer functionality

PostPosted: Wed Mar 09, 2016 9:18 am
by Andrei Costescu
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.

Re: streamFilesToServer functionality

PostPosted: Wed Mar 09, 2016 10:48 am
by tgs
Thank you Andrei for your replys!

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.

Regards Thomas

Re: streamFilesToServer functionality

PostPosted: Wed Mar 09, 2016 10:55 am
by Andrei Costescu
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 :).

Re: streamFilesToServer functionality

PostPosted: Sun Mar 13, 2016 6:28 pm
by tgs
Hi Andrei,

Andrei Costescu wrote: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
Code: Select all
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:
Code: Select all
Wrapped java.lang.IllegalArgumentException: Local file path doesn't make sense for the getRemoteDirList method


Regards Thomas

Re: streamFilesToServer functionality

PostPosted: Mon Mar 14, 2016 10:39 am
by Andrei Costescu
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:
Code: Select all
var _files = new Array();
_files = plugins.file.getRemoteFolderContents('/', '.jpg', 1);

Re: streamFilesToServer functionality

PostPosted: Thu Oct 20, 2016 2:22 pm
by swingman
Hello,

in my solution I load and stream files by

"plugins.file.streamFilesToServer(_file,_new_name,m_streamingDone)"

to the

"servoy.FileServerService.defaultFolder:"

set in servoy-admin on a Mac OS X server.

This works, but the files will be stored with owner rights "root:staff" and not "<username>:staff".
Why is Servoy server using "root" instead of "<username>"?


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...

Re: streamFilesToServer functionality

PostPosted: Thu Oct 20, 2016 10:31 pm
by swingman
I have found a work-around.

I use launchd to run a script every two minutes which changes the owner of any new files written to the directory. The script I run is
Code: Select all
#!/bin/bash

/usr/sbin/chown -R <USERNAME> <THE DIRECTORY YOU WANT TO CHANGE PREMISSIONS FOR>


Launchd runs scripts as root so it is allowed to make the change of ownership.