Uploading files in Servoy smart client and Servoy web client.

Servoy requires a single code base which is common for both the desktop and web. But Servoy also has it’s limitations and oneof them is file uploading in servoy smart client and web client. The following tip demonstrates how a developer can handle file uploading in smart client and web client.
File uploading in Smart Client

We need a file plug-in for open a dialog for selecting a file and saving into the servoy media field.

In the first line of the following example I have called file plug-in method for open file select method. Plugin method takes following parameters.

plugins.file.showFileOpenDialog([selectionMode(0=both,1=Files,2=Dirs)],[startDirectory(nulldefault/previous)],[multiselect(true/false)],[filterarray])=

1. var file = plugins.file.showFileOpenDialog(1,null,false,[‘jpeg’,’jpg’,’png’,’gif’]); 2. if(file){ 3. test_media = plugins.file.readFile(file); // Converting selected file into byte[] and saving into table field.
}

I have added file filter for selecting only images of specific formats only as reflected in the above code.
.

Here http://www.servoy-stuff.net/faq.php file plug-in is listed as web compatible but in my case it not working in web client. The problem is that whenever the above function is called in the web client the file dialog will open at where servoy server is installed. That means whenever a user calls this function to upload file, file dialog will open at server and user doesn’t aware of this effect.

When developer testing this functionality in web client at his end it seems working perfect but he gets know when server is different computer and client is on different computer.

File uploading in Web Client

We can not use file plug-in in web client for uploading file. So we need to place a media field on the form and make sure it is editable and display type is media field. When we open application in web client media field,we have three buttons for uploading file, preview the file and delete the file. Servoy itself handles the file uploading in web client.

150 150 Burnignorance | Where Minds Meet And Sparks Fly!