How does streamFilesToServer works ?

Hi all.

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

This is my code

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

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:

  • 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:

  • 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:

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:

  • 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:

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 :)

Hi ptalbot

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

/**
 * @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

I told you:

ptalbot:
[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.

Thanks a lot ptalbot :D

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.

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.

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)

Hi Johan.

You’re the right !!!

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

Best regards. Roberto Blasco.

What should the expected behavior be on the mac when using this code from Developer with a Smart Client debug session:

	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.

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.

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

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

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)

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

	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.

Maybe a problem on Mac OS X? I’ll have a look.

Hi Scott,

to create an ‘uploads’ folder in /server/webapps/ROOT/, the server plugin is relying on a path relative to the executable.

On WIndows/Linux launched from developer, this path resolves correctly, but on Mac OS X, it doesn’t since the executable is located in the Servoy.app bundle: Servoy.app/Contents/MacOS so the plugin was falling back to the home of the current user (have a look inside yours, you should have and uploads folder in there with your transferred files).

I have corrected this so that it take the Mac path into account, try the attached jar.

Johan: a patch follows ;)

Hi Patrick

I am trying to use streaming too, but it seems not to be working on my machine. I need to stream a blob in the database to the desktop of the client. I have tried to do this:

	var dir = plugins.file.showDirectorySelectDialog();
	if (dir){
			plugins.file.streamFilesFromServer(dir, image);
		
			}

but it simply does nothing…
Is there any documentation other than the sample included in Servoy 5.2?

Thanks

Bevil

Bevil

this version does not do blobs, only streaming file to/from server file based! (not blob-based)

Hey Harjo

It ONLY works with files? is there any way to work around it? write a blob to a local server temp file first and stream that? or would that undo the benefit of the streaming plugin?

I am in a desperate situation at the moment… My client’s in production system has stopped functioning because the datastream plugin has an error:

Failed: Server returned HTTP response code: 500 for URL:x.x.x.x:8080/servoy-service/StreamServiceServlet/

I have spent all day trying to troubleshoot this, to no avail, it just doesn’t work any more. In desperation, I tried to do the streamfilesfromserver thing, but if that is a dead end, I’ll have to continue fighting with datastream plugin.

:(

Bevil

have you contacted IT2BE?