This control to selects a file for upload. The control generates a input field and a "Browse" button. The "Browse" button activates the file browser and allows selecting the file interactively. To use the selected file in the fileUpload control you need another control, for example, a button named "Start upload", to finally start the upload.
If you use a fileUpload control in the JSP you must set the encondingType attribute of the form control to " multipart/form-data ".
Example: <hbj:form encodingType="multipart/form-data" >
id
Identification name of the fileUpload.
accept
Defines the accepted MIME type.
maxLength
Defines the maximum file size in byte allowed for the upload. By default there is no limit.
size
Defines the width of the fileUpload inputField in characters. The frame of the inputField is adjusted accordingly considering the actual text font and the design attribute.
Attributes |
M |
Values |
Usage |
---|---|---|---|
id |
* |
String (cs) |
Taglib id="chooseInputFile" Classlib setId ("chooseInputFile") |
accept |
String |
Taglib accept="text/rtf" Classlib setAccept ("text/rtf") |
|
maxLength |
Numeric (-1) |
Taglib maxlength="125000" Classlib setMaxlength ("125000") |
|
size |
Numeric (20) |
Taglib size="30" Classlib setSize ("30") |
using the taglib
<hbj:form encodingType="multipart/form-data"> <hbj:fileUpload id="myfileupload" maxLength="125000" size="50" /> </hbj:form>
Result
In an application you usually have an additional control, usually a button, to start
the upload once the file has been selected with the "Browse..." button.
Here we show what the server program 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.
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); } }