How does streamFilesToServer works ?

Questions, tips and tricks and techniques for scripting in Servoy

How does streamFilesToServer works ?

Postby Roberto Blasco » Tue Sep 07, 2010 9:17 pm

Hi all.

I've been trying to use this new feature in web client... what something goes wrong

This is my code

Code: Select all
function btn_select_file(event) {
   
   plugins.file.showFileOpenDialog( callback_method_select_file);
}

function callback_method_select_file(){

   file = arguments[0];
   
   if (file) {
      plugins.file.streamFilesToServer( file, callback_stream_file );
   }
}

function callback_stream_file(){
   
}


- Where the file goes in the server side?
- Can I say to the function the dirname of the server where to place the file?
- Is callback_stream_file() receiving any parameter?


Best Regards. Roberto.
Servoy 5.2
Windows XP, Ubuntu 10.04, Postgres 8
Un saludo. Roberto.

Madrid - Spain
Tfno: (+34) 625653066
E-mail: roberto.blasco.serrano@gmail.com
User avatar
Roberto Blasco
007
 
Posts: 355
Joined: Tue Apr 08, 2008 7:18 pm
Location: Madrid / Spain

Re: How does streamFilesToServer works ?

Postby ptalbot » Wed Sep 08, 2010 3:53 am

Hi Roberto,

not sure what's not working for you on web client, can you tell us more?
[EDIT] Actually found out that there is something wrong when the file is coming from the web client showFileOpenDialog callback: it is a special type of JSFile (UploadData) which was not properly taken into account, will write a patch for this (hopefully) before 5.2.2.[/EDIT]

Roberto Blasco wrote:- Where the file goes in the server side?

if you have a look at the admin page of Servoy, in the plugins page, you will see that there is a new server property for the file plugin, which is called "servoy.FileServerService.defaultFolder", this is where you can set up the (server-side) root path that streamFilesToServer (and streamFilesFromServer) will use.

If you don't provide a path, the plugin will create an "/uploads/" folder in your "/Servoy/application_server/server/webapps/ROOT/" folder and use it as default. The files uploaded there will be directly accessible from a http url like http://yourServerUrl/uploads/yourfile

Note that this path is not secured so it is advised that you setup a path that will not be visible although it might be handy to use for public images and public files... it's really up to you.

Roberto Blasco wrote:- Can I say to the function the dirname of the server where to place the file?

Now, everything you upload will go in that folder, but note that you can use a second parameter to set up a path relative to that folder, like so:
Code: Select all
plugins.file.streamFilesToServer( file, "/asubfolder/anotherone/" + file.getName(), callback_stream_file );

The relative path must always start with "/" if you use that second parameter.

Roberto Blasco wrote:- Is callback_stream_file() receiving any parameter?

The callback_stream_file will receive parameters:
- file (depending on the version of Servoy you use it can be a String (a path like "/folder/file.ext") - for 5.2 - or a JSFile - for 5.2.1)
- exception if any exception occured (in which case file will probably be null

So you callback_stream_file can be written like that:

Code: Select all
function callback_stream_file( file, ex ) {
    if (ex) {
        // do something with the exception:
       application.output( ex, LOGGINGLEVEL.ERROR) ;
    } else {
        application.output( file.getAbsolutePath() );
    }
}


And in 5.2.2 you will also have a new JSProgressMonitor object that will give you some feedback about the transfers (both ways), allowing you to give feedback to your users :)
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: How does streamFilesToServer works ?

Postby Roberto Blasco » Wed Sep 08, 2010 7:37 pm

Hi ptalbot

I've been tested what you said, but it doesn't work on webclient


Code: Select all
/**
* @properties={typeid:35,uuid:"7C0C089E-7299-4D0D-A923-EC44E1414B00"}
*/
var filename = "";

/**
* Perform the element default action.
*
* @param {JSEvent} event the event that triggered the action
*
* @properties={typeid:24,uuid:"AAD1E061-C945-4DE7-BF02-DDA271701ADE"}
*/
function btn_select_file(event) {
   
   plugins.file.showFileOpenDialog(1,null,false,null,callback_select_file,"Select file to upload");
}

/**
* @properties={typeid:24,uuid:"56BB077F-D8A3-448F-BB54-B3BA39DA4CBD"}
*/
function callback_select_file(){

   var file = arguments[0];
   application.output("callback_select_file : " + file)
   
   plugins.file.streamFilesToServer(file,null,callback_stream_file)   
}

/**
* @properties={typeid:24,uuid:"A4B150B6-173B-4782-9026-B616AD83C544"}
*/
function callback_stream_file(){
   
   application.output("callback_stream_file : " + arguments[0])
   application.output("callback_stream_file : " + arguments[1])
   application.output("callback_stream_file : " + arguments[2])
}

Executed on SmartClient this is the console ouput

callback_select_file : [C:\Documents and Settings\Administrador\Mis documentos\Descargas\stels_xml.tar.gz]
callback_stream_file : /stels_xml.tar.gz
callback_stream_file :
callback_stream_file : undefined

The upload is sucessfull :D

Executed on WebClient this is the console output

callback_select_file : [UploadData[name:t_adm_tablas.csv,contenttype:application/octet-stream]]

The upload doesn't works :(


Behavior and parameters passed are diferent on web/smart client

- Callback Funtion in plugins.file.streamFilesToServer is not executed
- What kind of object is [UploadData] when web client?


Greetings. Roberto Blasco.
Servoy Version: 5.2.1 - build 999
Windows XP, Ubuntu 10.04, Postgres 8
Attachments
tmp.servoy
(3.72 KiB) Downloaded 295 times
Un saludo. Roberto.

Madrid - Spain
Tfno: (+34) 625653066
E-mail: roberto.blasco.serrano@gmail.com
User avatar
Roberto Blasco
007
 
Posts: 355
Joined: Tue Apr 08, 2008 7:18 pm
Location: Madrid / Spain

Re: How does streamFilesToServer works ?

Postby ptalbot » Wed Sep 08, 2010 10:14 pm

I told you:
ptalbot wrote:[EDIT] Actually found out that there is something wrong when the file is coming from the web client showFileOpenDialog callback: it is a special type of JSFile (UploadData) which was not properly taken into account, will write a patch for this (hopefully) before 5.2.2.[/EDIT]


An UploadData object is a special wrapper around byte[] used in the web client, it is not a file, nor a JSFile, which is why it has to be explicitely treated, which was not the case in the current version.

I have found a way to do it, will send you a preview jar for you to test, and will send a patch to Servoy for this.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: How does streamFilesToServer works ?

Postby Roberto Blasco » Wed Sep 08, 2010 10:32 pm

Thanks a lot ptalbot :D
Un saludo. Roberto.

Madrid - Spain
Tfno: (+34) 625653066
E-mail: roberto.blasco.serrano@gmail.com
User avatar
Roberto Blasco
007
 
Posts: 355
Joined: Tue Apr 08, 2008 7:18 pm
Location: Madrid / Spain

Re: How does streamFilesToServer works ?

Postby jcompagner » Thu Sep 09, 2010 12:07 pm

patrick already send a patch, and i replied so i think patrick will come up with a slightly better patch for this (handling large files)
this will be fixed in 5.2.2

But the question is, why would you use streamToServer in a webclient environment
or is this just common code between a smart en web? (then i understand)

because streamTo or From server doesnt really make much sense in my eyes if you ask me..
you are already on the server... and you can save it just fine where you want.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: How does streamFilesToServer works ?

Postby Roberto Blasco » Thu Sep 09, 2010 6:08 pm

Hi jcompagner

jompagner wrote:

But the question is, why would you use streamToServer in a webclient environment
or is this just common code between a smart en web? (then i understand)

because streamTo or From server doesnt really make much sense in my eyes if you ask me..
you are already on the server... and you can save it just fine where you want.


I need an application for file management. These files must be uploaded and "proccessed" on the server side without the need of anybody to be present in the client side.

Why webcient? ..... because smartclient can't do it without plugins, and I need a callback function to know if file is well uploaded to continue with my Servoy methods.

Greetings. Roberto Blasco.
Un saludo. Roberto.

Madrid - Spain
Tfno: (+34) 625653066
E-mail: roberto.blasco.serrano@gmail.com
User avatar
Roberto Blasco
007
 
Posts: 355
Joined: Tue Apr 08, 2008 7:18 pm
Location: Madrid / Spain

Re: How does streamFilesToServer works ?

Postby jcompagner » Thu Sep 09, 2010 6:11 pm

that doesn't answer my question.
Why do you use streamFilesToServer if you are already working in a webclient??

If you are on a webclient the files at the moment you call streamFilestoServer are already on the server, so why tell it to stream again to the same machine?

just use plugins.file.writeFile(JSFile_pointing_to_a_file_on_server,bytes)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: How does streamFilesToServer works ?

Postby Roberto Blasco » Thu Sep 09, 2010 6:56 pm

Hi Johan.

You're the right !!!

Thank you to open my eyes :D :D :D

Best regards. Roberto Blasco.
Un saludo. Roberto.

Madrid - Spain
Tfno: (+34) 625653066
E-mail: roberto.blasco.serrano@gmail.com
User avatar
Roberto Blasco
007
 
Posts: 355
Joined: Tue Apr 08, 2008 7:18 pm
Location: Madrid / Spain

Re: How does streamFilesToServer works ?

Postby sbutler » Mon Sep 13, 2010 2:17 am

What should the expected behavior be on the mac when using this code from Developer with a Smart Client debug session:
Code: Select all
   var file = plugins.file.showFileOpenDialog( 1, null, false, null, null, 'Choose a file to transfer' );
   if (file) {
      plugins.file.streamFilesToServer( file);
   }


Should the plugin still stream the file to the server (which is same machine in developer) ? I'm testing on a Mac using 5.2.1 and it doesn't work. File isn't streamed, and the /upload folder never gets created.
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: How does streamFilesToServer works ?

Postby ptalbot » Mon Sep 13, 2010 3:08 am

Hi Scott,
yes, it should stream the file from the client to the server on the same machine, except that (and I saw that while I was trying to make it work for web client), if the second parameter is not used in streamFilesToServer() there is a NPE in the Runnable which is not reported, and the process fails...
This is part of the patch I sent to Johan, in the meantime, try adding a second argument (for example a path like "/" + file.getName()) and it should work.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: How does streamFilesToServer works ?

Postby michel » Mon Sep 13, 2010 11:51 am

For webclient johan says:

just use plugins.file.writeFile(JSFile_pointing_to_a_file_on_server,bytes)


That is correct, but when this is done in a webclient (run from developper 5.2.1) the following error appears in the servoy_log

Code: Select all
2010-09-13 09:57    http-8080-6    ERROR    com.servoy.j2db.util.Debug    error executing event com.servoy.j2db.plugins.ClientPluginAccessProvider$MethodExecutor@1992770
java.lang.StackOverflowError
     at com.servoy.extensions.plugins.file.WebFileProvider.js_writeFile(Unknown Source)
     at com.servoy.extensions.plugins.file.FileProvider.js_writeFile(Unknown Source)
     at com.servoy.extensions.plugins.file.WebFileProvider.js_writeFile(Unknown Source)
     at com.servoy.extensions.plugins.file.FileProvider.js_writeFile(Unknown Source)
     at com.servoy.extensions.plugins.file.WebFileProvider.js_writeFile(Unknown Source)
     at com.servoy.extensions.plugins.file.FileProvider.js_writeFile(Unknown Source)
     ...
Michel van Klink
Vision Development
michel
 
Posts: 186
Joined: Mon Sep 22, 2008 10:53 am
Location: Boskoop, The Netherlands

Re: How does streamFilesToServer works ?

Postby jcompagner » Mon Sep 13, 2010 1:50 pm

that is a know bug already fixed for the next release, you can download it here:

http://downloads.servoy.com/downloads/b ... n/file.jar

(this includes the latest patch from patrick)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: How does streamFilesToServer works ?

Postby sbutler » Tue Sep 21, 2010 9:17 pm

ptalbot wrote: try adding a second argument (for example a path like "/" + file.getName()) and it should work.


Code: Select all
   var file = plugins.file.showFileOpenDialog( 1, null, false, null, null, 'Choose a file to transfer' );
   if (file) {
      plugins.file.streamFilesToServer( file, "/" + file.getName());
   }


Unfortunately it still doesn't work. Using Mac 10.6.4, Java 1.6.0_20. servoy.FileServerService.defaultFolder hasn't been changed (still defaulted). The upload folder never gets created, and there are no errors in the log.
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: How does streamFilesToServer works ?

Postby ptalbot » Tue Sep 21, 2010 9:35 pm

Maybe a problem on Mac OS X? I'll have a look.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Next

Return to Methods

Who is online

Users browsing this forum: No registered users and 4 guests