BBjFileUpload::getFieldName

Description

In BBj 14.0 and higher, this method returns the name of the HTML element posted to the servlet with a BBjFileUpload object.

Syntax

Return Value

Method

string

getFieldName()

Parameters

None.

Return Value

Returns a string containing the name of the HTML form element.

Example

Copy

BBjFileUpload Example

REM Obtain the instance of the BBjAPI object
LET myAPI!=BBjAPI()
data! = BBjAPI().getServletData(err=publish)

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()
    response!.setContentType("text/html")
    open(chan)"JSERVLET"
    print(chan)"<html><body><h1>Hello BBj!</h1>"
    declare auto BBjVector files!
    files! = request!.getFileUploads()
    sz = files!.size()
    if sz then
      declare BBjFileUpload uploadFile!
      print(chan)"There were " + str(sz) + " files uploaded.<br>"
      for i=0 to sz-1
        uploadFile! = cast(BBjFileUpload,files!.get(i))
        print(chan)"Field:" + uploadFile!.getFieldName()
        print(chan)"- Name:"+ uploadFile!.getOriginalName()
        print(chan)"- Temp Name:"+ uploadFile!.getTempName()
        print(chan)"- Type:"+ uploadFile!.getContentType()
        print(chan)"- Size:"
        print(chan)uploadFile!.getContentLength()
        print(chan)"<br>"
      next i
    else
      print(chan)"There were no files uploaded, please upload some:<br>"
      print(chan)"<form id='upload' method='post' action='upload' enctype='multipart/form-data' >"
      print(chan)"<input id='file1' name='file1' type='file' /><br>"
      print(chan)"<input id='file2' name='file2' type='file' /><br>"
      print(chan)"<input id='file3' name='file3' type='file' /><br>"
      print(chan)"<input type='submit' value='submit' id='submit' />"
      print(chan)"</form>"
 
    fi
    print(chan)"</body></html>"
    close(chan)
  methodend
classend

publish:

admin! = BBjAPI().getAdmin("admin", "admin123")
registry! = admin!.getServletRegistry()
config! = BBjAPI().getConfig()
appServer! = admin!.getWebAppServer()

application! = appServer!.makeEmptyAppConfig()
application!.setProgramName(pgm(-1))
application!.setWorkingDirectory(dsk("")+dir(""))
application!.setConfigFile( BBjAPI().getConfig().getCurrentCommandLineObject().getConfigFile())
application!.setClasspathName(BBjAPI().getConfig().getCurrentCommandLineObject().getOriginalClasspathName())

bridgeurl$="/upload"
registry!.unpublish(bridgeurl$, err=*next)
registry!.publish(bridgeurl$, application!)

release

See Also

BBjAPI

BBjFileUpload

BBjHttpRequest

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