ShowTable of Contents
Summary: Currently the IBM® Lotus® Domino® 8.5 XPage upload control allows you to upload a file into an XPage application. In certain cases, however, you may want to limit what types of files a user can upload. This article describes how to configure the upload control for your needs and how to alert users when incorrect file types are submitted.
Introduction
Does your application allow users to upload images, but you find that all types of files are being uploaded? Do you want to prevent users from uploading executable files into your application? This article explains how to configure the XPage upload control, to limit what MIME types can be uploaded into your application. MIME, or
Internet Media Type as it is now referred to, describes the content that is being uploaded into your application.
Adding the upload control to your XPage or custom control
You can add the upload control to any XPage or custom control by simply dragging it from the core controls panel in Lotus Domino Designer and placing it in the desired location (see figure 1).
Figure 1. Upload control in an XPage
To limit the file upload control to accept only a certain MIME type:
1. Once you have the control in place, select the Properties tab > All Properties for the control (see figure 2).
2. Under the Property column, select the accept property, and then click on the Value column. You will see a drop-down list of default file types from which to choose.
Figure 2. List of default file types
This is fine if you want the file upload control to accept only one MIME type, but what if you need a MIME type that is not listed, or you need to accept multiple MIME types? In these cases, you can compute the value of the accept property so that you can accept a file type that is not listed, or accept multiple file types.
To do this, click on the blue diamond (on the far right-hand side in figure 2 above) and select compute value. If you want the upload control to accept only images, you can compute the value as shown in figure 3, separating each MIME type with a comma.
Figure 3. JavaScript expression to compute the accept property value
Click OK; you now see the computed value for the accept property in the Value column, as shown in figure 4.
Figure 4. Computed value displayed in Value column
Using the file download control to find MIME types
What if you want to add a new MIME type but are unsure what the MIME type is for a given file, such as a PDF?
To help in figuring out what a MIME type is for a given file, you can use the file download control along with the file upload control to display the MIME type for any file (see figure 5).
Figure 5. File download control from a Web browser
To add the download control to your XPage or custom control, simply drag the control from the core controls panel in Lotus Domino designer and add it to the desired location.
Once you've added the control, under the Properties tab, select File Download, and in the Options section make sure Type (the default) is selected (see figure 6).
Figure 6. File Download options
Now, before restricting the upload control to certain MIME types, you'll be able to verify the MIME types before you add them to the upload control.
Notifying the user when an invalid file is submitted
If you are configuring the upload control to accept only certain MIME types, you may want to alert users when they try to upload a file whose MIME type is not allowed for upload. To do this:
1. Add the message control to your XPage or custom control.
2. Next, under the Properties tab, select Display Error, and in the Name field enter a name for the control.
3. Click on the drop-down for the “Show error messages for” field andbind it to the field that would generate an error in the case of the upload control (see figure 7).
Figure 7. Message control configuration
Once the message control is configured, you'll see the following message if, for example, the upload control does not allow MIME types of text/plain:
Conclusion
With the new XPage upload control you now have greater control over what type of files your application will accept. This provides greater flexibility, for example, by ensuring that only image files are uploaded when you ask for a profile photo or ensuring that only spreadsheet files are uploaded when you request expense reports.
Resources
Notes and Domino information center:
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp
IBM Lotus Support document, “Knowledge Collection: XPages”:
http://www-01.ibm.com/support/docview.wss?uid=swg27014929
IBM Lotus Support document, "Preview in Web Browser" option grayed out for custom controls”:
http://www-01.ibm.com/support/docview.wss?uid=swg21366584
About the author
Kevin Giles is an IBM Advisory Software Engineer currently working as an application developer and system administrator for the IBM developerWorks® Lotus Web site. He joined Iris Associates, now part of IBM, in 1997, where he worked on the original Notes.net Web site. In past roles he also worked as a quality assurance tester for Lotus Domino. Kevin is an IBM Certified Advanced Application Developer.