BBjspWebRequest::getFileUpload (Deprecated)

The BBJSP system is deprecated. For new development, use BBxServlet.

Description

In BBj 16.0 and higher, this method returns a BBjFileUpload object available in a BBjspWebRequest object.

Syntax

Return Value

Method

BBjFileUpload

getFileUpload(string name)

Parameters

Variable

Description

name

the 'name' of input element from the HTML form

Return Value

returns a BBjFileUpload object

Remarks

The example below demonstrates how to process uploaded files in a BBjspWebRequest and get the associated BBjFileUpload Object by name.

Example

This example demonstrates how this works in a BBJSP web-page

<%@ taglib uri='/WEB-CFG/tld/core.tld' prefix='c' %>
<html>
    <body>
        <h1>Hello from BBJSP</h1>
        <c:set var='upload' value='#request!.getFileUpload("thefile")'>
        <c:ifnotnull value='${thefile}'>
            You uploaded '${upload["OriginalName"]}'
            of type: ${uploadFile["ContentType"]}
            and Size: ${ uploadFile["ContentLength"]} bytes.
        </c:ifnotnull>
        <c:ifnull test=''>
            Please upload a file
            <br>
            <form id='upload' method='post' action='upload' enctype='multipart/form-data' >
                <input id='thefile' name='thefile' type='file' />
                <br>
                <input type='submit' value='submit' id='submit' />
            </form>
        </c:ifnull>
    </body>
</html>

This example demonstrates how this works in a BBJSP servlet

class public MyServlet

  field private BBjspWebRequest request!
  field private BBjspWebResponse response!
  field private BBjspWebSession session!
  
  method public void service(BBjspServletContext context!)
       
    #request! = context!.getRequest()
    #response! = context!.getResponse()

    resp!.setContentType("text/html")
    s!.write("<html><body><h1>Hello from BBJSP</h1>")
    upload! = #request!.getFileUpload("thefile")
    if upload! <> null() then
      declare BBjFileUpload uploadFile!
      uploadFile! = cast(BBjFileUpload,upload!)
      s!.write("You uploaded '")
      s!.write(uploadFile!.getOriginalName())
      s!.write("' of type:"+ uploadFile!.getContentType())
      s!.write(" and Size:")
      s!.write(uploadFile!.getContentLength())
      s!.write("bytes.<br>")
    else
      s!.write("Please upload a file<br>")
      s!.write("<form id='upload' method='post' action='upload' enctype='multipart/form-data' >")
      s!.write("<input id='thefile' name='thefile' type='file' /><br>")
      s!.write("<input type='submit' value='submit' id='submit' />")
      s!.write("</form>")
    fi
    s!.write("</body></html>")
  methodend
classend

See Also

BBJSP

BBjspWebRequest

BBjFileUpload