Runtime tools : Channels components : AJAX channel : Concepts : AJAX file upload request overview : File upload handler
  
File upload handler
This section provides a description of the file upload handler.
A file handler is a key component in the implementation of a file upload request. Below is an example configuration of a file handler in the btt.xml file. In the example, file handlers are defined under the fileHandlers kColl. An ID and implementation class must be specified for every file handler. The parameters of every file upload handler are configured and defined according to the implementation of the handler.
Example configuration of a file upload handler in the btt.xml file
<kColl id="channelHandlers">
<field id="initializer"
value="com.ibm.btt.channel.ChannelInitializer"/>
<!-- allow opera users accesss the internet banking -->
<kColl id="devices">
<field id="opera"value="html"description="contains"/>
</kColl>
<!--ajax channel configuration -->
<kColl id="ajax">
<field id="encoding" value="UTF-8"/>
<field id="cookies" value="true"/>
<field id="runInSession" value="true"/>
<field id="requestHandler" value="com.ibm.btt.cs.ajax.AjaxHtmlRequestHandler"/?
<field id="presentationHandler" value="com.ibm.btt.cs.ajax.AjaxHtmlPresentationHandler"/>
<!-- File handlers define all available file handlers for file upload widget.
You can extend to create a new file handler, and then configure it here. -->
<kColl id="fileHandlers">
<!-- sample handler, it can save and delete a file into file system with a file upload request -->
<kColl>id="sampleFileHandler">
<!-- implementation class of the handler -->
<field>id="implClass"value="com.ibm.btt.sample.SampleFileHandler"/>
<!-- how many milli-seconds later, the fileupload handler will timeout,
default value is 20 minutes -->
<fieldid="timeout"value="2000"/>
<!-- max file size that be allowed for the file upload handler -->
<field id="maxSize" value="62914560"/>
<!-- cache folder path of the file system, it is used to cache the upload
file when uploading -->
<field id="cachePath" value="c:\temp\fileupload\cache"/>
<!-- file fold on the server, uploaded files will saved under the folder
just support d:\er\wee" for DOS, or "/d/er/wee" for UNIX -->
<field id="filepath" value="c:\temp\fileupload\upload"/>
<!-- cache size, if file is bigger than the size, it will be saved in
file system or else if will be hold in memory. -->
<field id="memCacheSize" value="4096"/>
</kColl>
</kColl>
</kColl>
A sample file handler that is implemented to save the file upload request stream to a file system is included in the sample.
The AbstractFileHandler class provides an extension point for developers to enable customers to submit file upload requests on demand.
The AbstractFileHandler class contains the following eight methods:
initConfig()
Initializes the parameters that are required by the handler, e.g. maximum file size, file path, and file extension.
requestValidate()
Validates the request, e.g. whether file type is supported or whether the file size is too large.
saveFile()
Saves the file request stream to a file system such as a database or a remote server.
deleteFile()
Removes a file from the server side. The deleteFile() method also cancels an uploaded file from the browser side.
retrieveFile()
Retrieves a file from the server side.
OnRequestExpired()
A timeout value can be configured for a file handler. If the time that is required to process a file upload request exceeds the timeout value, the onRequestExpired() method is called to drop the file upload request. The uploaded file is then removed, and an error message is displayed on the browser.
updateContext()
Updates the processor or session context when a file upload request is complete. Subsequent file upload request operations can access the updated context to retrieve data.
getFileInfo()
This method aligns with the UI widget customization. This method returns a JSON object that is processed for the reply message of the file upload request.
Go up to
AJAX file upload request overview