UploadData Object

Hi all!

How can I get the file name from the UploadData Object?

function btn_select_file(event) {

	plugins.file.showFileOpenDialog( 1, null, false, null, callback_select_file, 'Selecciona un fichero' );
}

function callback_select_file(file){
    
    if (file) {
        application.output(file);
        plugins.file.streamFilesToServer( file, callback_stream_file );
    }
}

The function output is [UploadData[name:file_data.bin,contenttype:application/octet-stream]]

Best regards. Roberto.

How about file.getName()?

Hi Patrick.

I tried it before posting, and this was the output

Failed to execute the method of context batch_clave and name callback_select_file on the solution pgp
Java class “[Lcom.servoy.extensions.plugins.file.JSFile;” has no public instance field or method named “getName”. (C:\Documents and Settings\Administrador\servoy_workspace.5\pgp\forms\batch_clave.js#42)
at C:\Documents and Settings\Administrador\servoy_workspace.5\pgp\forms\batch_clave.js:42 (callback_select_file)

If I try to convert it to a JSFile Object

function callback_select_file(file){
	
	if (file) {
		var obj_file = plugins.file.convertToJSFile(file);
		application.output("File Name : " + obj_file.getName());
		plugins.file.streamFilesToServer( file, callback_stream_file );
	}
}

The output is

File Name : [Lcom.servoy.extensions.plugins.file.JSFile;@8e065

Best regards. Roberto.

Servoy 5.1.2
Windows XP / Ubuntu 10.04
Postgres 8

OK. Don’t know why exactly but I will have a look.

Still, I thought you were going to use JSFile.writeXXX() in the web client?
Because for smart client, you should receive a proper JSFile directly from the call to plugins.file.showFileOpenDialog() (no need for a callback).

Thanks Patrick.

I know I must use JSFile.writeXXX() :D

I tried it with the plugin just for curiosity… :roll:

Best regards. Roberto.

Hi Roberto,

curiosity is good! :)

Actually you should try converting it using convertToRemoteJSFile() because by the time it gets to your callback method it is already on the server…

    function callback_select_file(files){
       
       if (files && files.length > 0) {
          application.output("File Name : " + obj_files[0].getName());
          plugins.file.streamFilesToServer( files[0], callback_stream_file );
       }
    }

the callback gets an array of files not just 1 file, there is multi select support…

Of course! Johan is right, totally forgot about it, sorry :)

Thanks Patrick, Johan.

Works perfectly. :-)

Greetings. Roberto.