streamFilesToServer functionality

Questions and answers on developing, deploying and using plugins and JavaBeans

streamFilesToServer functionality

Postby tgs » Tue Feb 16, 2016 11:42 am

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
Last edited by tgs on Tue Mar 08, 2016 1:41 pm, edited 1 time in total.
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 833
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: streamFilesToServer functionality

Postby tgs » Tue Mar 08, 2016 1:47 pm

Any help and/or information would be appreciated.

Thomas
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 833
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: streamFilesToServer functionality

Postby Andrei Costescu » Tue Mar 08, 2016 9:04 pm

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)?
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 902
Joined: Tue Jun 26, 2007 3:14 pm

Re: streamFilesToServer functionality

Postby tgs » Tue Mar 08, 2016 9:42 pm

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?
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 833
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: streamFilesToServer functionality

Postby Andrei Costescu » Tue Mar 08, 2016 10:19 pm

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.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 902
Joined: Tue Jun 26, 2007 3:14 pm

Re: streamFilesToServer functionality

Postby tgs » Tue Mar 08, 2016 10:34 pm

Ahh ok, sorry. I'm currently a little confused...

Yes, the solution is running only with smart clients!

Is there any solution for this?
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 833
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: streamFilesToServer functionality

Postby Andrei Costescu » Wed Mar 09, 2016 9:18 am

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.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 902
Joined: Tue Jun 26, 2007 3:14 pm

Re: streamFilesToServer functionality

Postby tgs » Wed Mar 09, 2016 10:48 am

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
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 833
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: streamFilesToServer functionality

Postby Andrei Costescu » Wed Mar 09, 2016 10:55 am

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
Servoy
Andrei Costescu
 
Posts: 902
Joined: Tue Jun 26, 2007 3:14 pm

Re: streamFilesToServer functionality

Postby tgs » Sun Mar 13, 2016 6:28 pm

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
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 833
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: streamFilesToServer functionality

Postby Andrei Costescu » Mon Mar 14, 2016 10:39 am

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);
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 902
Joined: Tue Jun 26, 2007 3:14 pm

Re: streamFilesToServer functionality

Postby swingman » Thu Oct 20, 2016 2:22 pm

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...
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1157
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: streamFilesToServer functionality

Postby swingman » Thu Oct 20, 2016 10:31 pm

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.
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1157
Joined: Wed Oct 01, 2003 10:20 am
Location: London


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 5 guests