Adding a file upload component to a Web page

Use the File Upload component to create a way for users to upload a file to the server. This component consists of an input field and an associated Browse button.

The user can manually specify the file in the input field or can browse for a file by clicking Browse. To use a file upload component on a Faces JSP file:

  1. Drag a File Upload component from the Faces Components drawer on the palette to the Faces JSP file.

  2. In the Properties view for the File Upload component (fileupload), enter the value (in the

    Value field) to which you want to bind the file upload component. You can also click the browse button to search for a value. The value can be a byte[], a String (file content will be Base64 encoded) or a java.io.OutputString object. The file upload component is usually bound to data storage, such as a database or a JavaBean. When the page with the file upload component is submitted, the content of the file is stored in the specified location (a column in the database or a property of the bean).

  3. In the Validation panel of the Properties view:

    1. Check

      Value is required if you want to require that the user specify a file.

    2. Specify in MIME notation the types of files that the user can upload. Use MIME notation and separate file extensions with commas (for example: text/html, image/gif).

    3. Specify the file types you do not want the user to upload. Separate file extensions with commas (for example: xml, bat, exe).

    4. You can supply additional validation in the Value Changed event in the Quick Edit view. Click the button next to

      Click to create/edit custom validation code to switch to the Quick Edit view.

 

Related reference

File Upload