Control API for File Upload (fileUpload)

A control to select a file for upload. The control generates a input field and a "Browse" button. The "Browse" button activates the file browser and allows to select the file interactively. To use the selected file in the fileUpload control you need another control, e.g. a button named "Start upload", to finally start the upload.

 

Important note:
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.
attribute req. values default case sens. JSP taglib classlib
id yes String none yes id="chooseInputFile"  
accept no String none - accept="text/rtf" setAccept("text/rtf")
maxLength no Numeric -1 - maxlength="125000" setMaxlength(125000)
size no Numeric 20 - size="30" setSize(30)

 

 

Example
<hbj:form encodingType="multipart/form-data" >
   <hbj:fileUpload  id="myfileupload"
maxLength="125000"
size="50"
/> </hbj:form>

Result
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);
         }
     }