WebFileUploadEx Function

Action

Uploads a file to the web server. This function implements a RFC1867-compliant file upload function for form-based file upload in HTML.

WebFileUploadEx automatically recognizes a multipart form and a file upload. When uploading a file during recording, the Silk Performer Recorder automatically scripts the respective function and the uploaded file is added to the data files.

A file that is to be uploaded must be specified by a name-value pair in the following way:
"filename" := "<name of the input tag>;<file name>;<content type>";

Include file

WebAPI.bdh

Syntax

WebFileUploadEx( in sUrl  : string,
                 formUrl  : form,
                 formBody : form,
                 in fWait : double optional ): boolean;

Return value

  • true if the file is found and submitted successfully

  • false otherwise

Parameter Description
sUrl Complete URL to the file on the server
formUrl Form identifier used in the dclform section (see example below). The expanded form is added to the URL after the "?".
formBody Form identifier used in the dclform section (see example below). The expanded form is added to the body of the request. The Content-Length and Content-Type header are added automatically.
fWait Minimum time or minimum mean time that this function call has to last (optional). Default value is 0.0

Example

The form content in the dclform section is represented in an unencoded format to enhance readability and customizability. The data gets URL encoded on file upload. There are two possibilities to send data unencoded:

  • Add the query string as it should be sent to the server directly to the URL, for example, "http://www.comp.com/cgi/special?<don't>;[encode]/this". Note that blanks are encoded when this method is used.
  • Use WebUrlPostBin or WebFormPostBin to post data as provided to the Web server.
dcltrans
  transaction TWebFileUpload
  begin
    WebFileUploadEx("http://standardhost/data2html.asp", URL_FORM, FILE_UPLOAD_FORM);
  end TWebFileUpload;

dclform
URL_FORM:
  "ID" := "1234";
FILE_UPLOAD_FORM:
  "anyname"  := "anyvalue", 
  "filename" := "my_file;C:\\temp\\test.doc;application/msword";