Starting with OpenEdge 10.1A, WebSpeed supports upload of binary/BLOB data files, where previously only text files could be uploaded.
The following code is an example of how to create an HTML form that can upload a file:
ACTION="http://<yourhost>/<msngr path>/<msngr>/ping" METHOD="POST">
<INPUT type="file" name="filename">
To enable a WebSpeed application to accept binary/BLOB data from this form, you must do following:
- Upgrade WebSpeed Messenger to OpenEdge 10.1A or later. The Messengers in previous versions cannot accept BLOBs.
- The following WebSpeed ubroker configuration set in the Agent > Advanced Features page of the WebSpeed Transaction Server’s Properties sheet:
- Specify the upload directory where binary files are uploaded to: fileUploadDirectory
- Specify a maximum size for uploaded binary files. The maximum size is set with the binaryUploadMaxSize (bytes)
The "binaryUploadMaxSize=0" by default, which means that binary files are not allowed to be submitted with a web request. This supports to the behaviour of previous versions, which is not to upload binary files so there is no change in behaviour for existing applications:
file types that can be uploaded successfully are text file types, and so do not depend on the value of binaryUploadMaxSize
The WebSpeed administrator and/or application developer can then set it to any value greater than zero to enable and enforce the binary file size appropriate for the application. Enforcing the maximum size for binary files, provides them a means to limit the resources WebSpeed needs to process a file that the end-user submitted with the web request.
It can also set it to -1 if no file size limit for binary files needs to be imposed. Specifying a value lesser than -1, will have the same effect specifying -1 (although, one should not set it to a value less than -1).
3. The WebSpeed broker will need to be restarted after making these configuration changes.
- Write code to manipulate the uploaded binary file through its MEMPTR. This code should ensure that the uploaded file contains no malicious content before it is stored to disk. WebSpeed provides a new API function "get-binary-data" to return the file’s MEMPTR.
/* This example shows how to retrieve the data from a file passed on a given request,
and save it as a file with the same name to the WebSpeed agents working directory.
Note that 'filename' is the name of the field in the form that was posted. */
DEFINE VAR mFile AS MEMPTR NO-UNDO.
DEFINE VAR cfile AS CHAR NO-UNDO.
/* 'filename' refers to the name of the field in the form.
get-binary-data returns the contents of the file associated with the form field named 'filename'. */
ASSIGN mFile = get-binary-data("filename").
IF mFile <> ? THEN DO:
ASSIGN cfile = get-value("filename").
COPY-LOB FROM mFile TO FILE cFile NO-CONVERT.
<FORM ENCTYPE="multipart/form-data" ACTION="http://localhost/scripts/cgiip.exe/WService=wsbroker1/ping" METHOD="POST">
<INPUT type="file" name="filename">
When this code is run from an external procedure the following line should be placed at the top of the code to ensure the external procedure is in the web context.:
If the binaryUploadMaxSize
property value is not specifically changed for the WebSpeed Broker, it is set to the default value of 0 (zero). This will result in the following error when attempting to upload a binary file:
ERROR: Binary file upload is not supported. (8868)
The configuration setting can be changed by setting it in the code with:
<n> can be -1 (unlimited) or any value greater than or equal to 0 (zero) where the value is represented in bytes.
If binary files are not uploaded to the upload directory defined in the ubroker.conig (fileUploadDirectory), explicitly prepend the output of the following call to the file name which will provide the full path:
get-config("fileUploadDirectory") + "\" + cfile.
DEFINE VARIABLE oFile AS CHARACTER NO-UNDO.
oFile = get-config("fileUploadDirectory") + "\" + cfile.
COPY-LOB FROM mFile TO FILE oFile NO-CONVERT.
binaryUploadMaxSize =<size in bytes>