Programming Tip
In an application you usually have an additional control, usually abutton, to start
the upload once the file has been selected with the "Browse..." button.
Here we show what the server programm has to do when the user starts the upload.
In our example we define a button with an "onClick" event and specified as "onClick"
event handling method "onLoadFile". The "onLoadFile" method does the upload handling.
Example
public void onLoadFile(Event event) {
FileUpload fu = (FileUpload) this.getComponentByName("myfileupload");
// this is the temporary file
if (fu != null) {
// Output to the console to see size and UI.
System.out.println(fu.getSize());
System.out.println(fu.getUI());
// Get file parameters and write it to the console
IFileParam fileParam = fu.getFile();
System.out.println(fileParam);
// Get the temporary file name
File f = fileParam.getFile();
String fileName = fileParam.getFileName();
// Get the selected file name and write ti to the console
ivSelectedFileName = fu.getFile().getSelectedFileName();
System.out.println("selected filename: "+ivSelectedFileName);
}
}
|