BBjHttpRequest::getFileUpload

Description

In BBj 14.0 and higher, this method returns a BBjFileUpload object available in a BBjHttpRequest object.

Syntax

Return Value

Method

BBjFileUpload

getFileUpload(string name)

Parameters

Variable

Description

name

Specifies the name of the HTML form field element.

Return Value

Returns aBBjFileUpload.

Remarks

The example below demonstrates how to upload a file to a servlet and get the associated BBjFileUploadObject by name.

Example

REM Obtain the instance of the BBjAPI object

LET myAPI!=BBjAPI()

MyServlet! = new MyServlet()

 

data!.setCallback(data!.ON_WEB_CONNECTION, myServlet!, "myMethod")

 

PROCESS_EVENTS

 

class public MyServlet

  method public void myMethod(BBjServletEvent p_event!)

    LET chan = UNT

    request! = p_event!.getHttpRequest()

    response! = p_event!.getHttpResponse()

    resp!.setContentType("text/html")

    open(chan)"JSERVLET"

    print(chan)"<html><body><h1>Hello BBj!</h1>"

    upload! = request!.getFileUpload("thefile")

    if upload! <> null() then

      declare BBjFileUpload uploadFile!

      uploadFile! = cast(BBjFileUpload,upload!)

      print(chan)"You uploaded '"

      print(chan)uploadFile!.getOriginalName()

      print(chan)"' of type:"+ uploadFile!.getContentType()

      print(chan)" and Size:"

      print(chan)uploadFile!.getContentLength()

      print(chan)"bytes.<br>"

    else

      print(chan)"Please upload a file<br>"

      print(chan)"<form id='upload' method='post' action='upload' enctype='multipart/form-data' >"

      print(chan)"<input id='thefile' name='thefile' type='file' /><br>"

      print(chan)"<input type='submit' value='submit' id='submit' />"

      print(chan)"</form>"

    fi

    print(chan)”</body></html>”

    close(chan)

  methodend

classend

See Also

BBjAPI

BBjServletEvent

BBjHttpRequest

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.