A question about web-enabled showFileOpenDialog()

Questions, tips and tricks and techniques for scripting in Servoy

A question about web-enabled showFileOpenDialog()

Postby guerry » Tue Mar 15, 2011 11:33 pm

Hi all,

I am using Servoy 5.2.4 on Windows 7. I am using showFileOpenDialog in the web client to select one or more files. After selecting the files on the client, I am unable to see each files path and absolutePath values. I have tested on Firefox 3.6 and Chrome 10.

Here is the code:

Code: Select all
function selectFiles(event) {
   plugins.file.showFileOpenDialog(0,null,true,null,inspectFiles,"Select Files for Upload")
}

function inspectFiles(files) {
   if (files) {
      for (i in files) {
         var file = files[i];
         application.output('name: ' + file.getName());   
         application.output('path: ' + file.getPath());   
         application.output('absolute path: ' + file.getAbsolutePath());
      }
   }
}


The output is:

Code: Select all
name: IT Testing.doc
path:
absolute path:


Thanks,

Guerry
guerry
 
Posts: 37
Joined: Tue Nov 09, 2010 4:51 pm

Re: A question about web-enabled showFileOpenDialog()

Postby jcompagner » Wed Mar 16, 2011 11:35 am

what absolute file path are you expecting the see?
From the client? That has no use.

The thing is that in the call back method of the showFileOpenDialog in the webclient, you don't get real files.
You get an in memory cached binary data object. That only has a simple name (and the content type could also be set)
It is not really a file on your server, you have to write that first your self with plugins.file.writeFile("serverpathname", file.getBytes());

So the only thing you really can work with are the bytes and the simple name.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: A question about web-enabled showFileOpenDialog()

Postby guerry » Wed Mar 16, 2011 6:04 pm

In our application, I can see the original client path information being helpful from user perspective, albeit historical perhaps. However, that is not how I was using intending to use it in this instance.

My pattern of use is probably non=typical. I'm using showFileOpenDialog for user to select files for eventual upload. "Eventual" as there are other user operations that occur before the files are actually uploaded (collecting metadata, etc.). In my initial case, I thought I'd collect the path+name information from the client, and hold onto that information until I hit the point of upload. Then I'd reconstitute the JSFile objects using the path+name info, and then write the files to the server.

As it stands, I cache the File objects until they are needed, and then use them. This is extra code since the path+name data fits into the information flow I already had.
guerry
 
Posts: 37
Joined: Tue Nov 09, 2010 4:51 pm

Re: A question about web-enabled showFileOpenDialog()

Postby jcompagner » Wed Mar 16, 2011 6:09 pm

the browsers just don't send that information (i think IE did but most of them don't)
also if you have a JSFile object, the file is uploaded
but i guess you keep them on the server for a while and "commit" them when the user is really done?

Be careful with that if the files are quite big...
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: A question about web-enabled showFileOpenDialog()

Postby guerry » Wed Mar 16, 2011 8:27 pm

I misspoke. I'm holding onto the File objects returned by the showFileOpenDialog callback. At that point, the actual files are not transferred to the server yet, if I understand correctly, since I've not done a writeFile or streamToServer.

That said, it's not readily apparent to the neophyte which Servoy actions execute on the web client as JavaScript in the browser and which on the server. Swim lane diagrams or some such for these types of interactions would go a long way.
guerry
 
Posts: 37
Joined: Tue Nov 09, 2010 4:51 pm

Re: A question about web-enabled showFileOpenDialog()

Postby jcompagner » Wed Mar 16, 2011 11:20 pm

no those are already on the server..

In your own code so in scripting every thing is in the client, the difference is that for the smart client his runs on the pc of where the smart client runs
and for the webclient the client code runs in on the server. The browser just displays the output/ui.

So when the user does a file upload and you have a reference to it it is already in the client So for a webclient it is already uploaded to the server,
Streaming also doesn't make much sense for the webclient, because you stream within the same machine/java process.
writeFile only means that you store the bytes that you now have on memory to disk (on the server if you use really write it to a File object on the server, writeFile can also be used to write the file back to the client, so it has 2 usages)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: A question about web-enabled showFileOpenDialog()

Postby guerry » Thu Mar 17, 2011 4:59 am

Ah! Okay. That will simplify my code!

When using writeFile from server to client, how is the file represented there? Disk? Memory? If disk, can you define a destination directory, or know where it was written? I'd presume not....
guerry
 
Posts: 37
Joined: Tue Nov 09, 2010 4:51 pm

Re: A question about web-enabled showFileOpenDialog()

Postby jcompagner » Thu Mar 17, 2011 10:16 am

no writeFile("myname.ext", bytes);

will just popup a save as dialog on the client with that name prefilled in where the client then can save it anywhere it wants.
You can't really target anything (you don't know what you can target any also..)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Methods

Who is online

Users browsing this forum: No registered users and 19 guests