Online documentation - Websydian v6.0

Users Guide | Patterns Reference | WebsydianExpress | Search

 

Upload

Prerequisites

Background

The figure below shows the steps involved when a upload request is sent to a Websydian application.

Figure 1: Flow for an upload request

  1. The browser sends a request to the web server including one or more files to be uploaded to the server.
  2. The relay service servlet saves the files to a folder (configured in the property file).
  3. The relay service servlet sends information about the files to the application service.
  4. The application service uses a service function to retrieve the information about each file (including the filename).
  5. Using the information from the previous step the application service then reads and processes the files. If the file should be preserved for later use the application service must copy/move it to another location.
  6. The application service creates a response page to the user (by calling a page generator function).
  7. The relay service servlet deletes the file created in step 1).
  8. The response page is sent to the browser.

Steps 1 - 3 and 7 - 8 are handled automatically by the Websydian runtime. Steps 4 - 6 must be handled by the application developer in the event handler function.

Steps for Implementing Upload

Relay service servlet

Upload must be enabled in the relay service servlet. This is done by setting the following properties in the property file:

Property Description Default
servlet.upload Enables upload. Legal values are TRUE and FALSE (case insensitive). FALSE
servlet.upload.tempfolder The folder where the uploaded files are temporarily stored. Examples could be:
  • c:/temp
  • /myapp/uploadfilestemp
The temporary folder used by the Java virtual machine
servlet.upload.maxfiles The maximum number of files that can be uploaded in one request. 5

If you want to upload larger files it might be necessary to adjust the property servlet.contentlength.max which determines the maximum size of a request.

Please refer to Servlet Relay Service Options for more information.

For security reasons it is recommended that the temporary folder is set to a folder that does not contain any other files.

Application service

To enable upload for an event handler function apply the following steps:

  1. Create a text field and insert it in the WebInput variable. For convenience the field can inherit from WSYBASE/FormFieldName, but this is not necessary. The only requirement is that the field is of type Character and is long enough to contain its own implementation name.
  2. In the edit point '0 call to build of document' insert a call to the function WSYUTIL/GetUploadedFilesInfo. Map with the field in step 1) and WsyBase<ConnectionPointer>
  3. GetUploadedFilesInfo will return the information displayed in the table below.
    Output field Description
    OriginalFilename The original name of the file.
    ContentType The content type of the file. This field will be blank if no content type was supplied by the client.
    Charset The character set encoding used in the file. This field will be blank if no character set information was supplied by the client.
    UploadedFile The name of the temporary file stored by the relay service. If no file was uploaded this field will be blank.

    The file is stored in the folder specified by the relay service servlet property servlet.upload.tempfolder (see Relay service servlet for more information).

    Please note that the temporary file returned in the field UploadedFile will be deleted immediately after the request has been processed.

    So if you want to keep the file it must be moved/copied to another location.

    Use the information above to process the file. 
  4. The event handler must then call a page generator function which generates a response page to the user.
  5. Generate and build the page generator, the scoped event handler, and the document template generator functions.
  6. After executing the document template generator change the created input field in the template from type TEXT to type FILE.
    The line to be changed will look something like this:
    <P>Upload file<INPUT TYPE="TEXT" NAME="WU6A" VALUE="/(WU6A)" MAXLENGTH="128" SIZE="64"></P>
    In the above line change TYPE="TEXT" to TYPE="FILE".
  7. In the template add the attribute enctype="multipart/form-data" to the FORM that contains the input field in 4). E.g:
    <FORM ACTION="/app" NAME="D7UPLEVN" METHOD="POST" enctype="multipart/form-data">

If you want to upload more than one file in one request you repeat step 1 to 6 for each file you want to upload creating a new field in WebInput for each uploaded file.