Article

How to upload binary file through Webspeed?

« Go Back

Information

 
Article Number000010745
EnvironmentProduct: OpenEdge
Version: 10.1x, 11.x
OS: All Supported platforms
Other: WebSpeed
Question/Problem Description
How to upload binary files through WebSpeed?
How to upload BLOBs through WebSpeed?
How to use get-binary-data?
Steps to Reproduce
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution
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:
<HTML><BODY>
    <FORM ENCTYPE="multipart/form-data"  
          ACTION="http://<yourhost>/<msngr path>/<msngr>/ping" METHOD="POST">
    <INPUT type="file" name="filename">
    <INPUT type="submit">
    </FORM>
</BODY></HTML>

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:
    1. Specify the upload directory where binary files are uploaded to: fileUploadDirectory
    2. 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.
Example:
/* 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. */

{src/web/method/cgidefs.i} 

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. 
END. 

{&OUT} 

'<HTML><BODY> 
<FORM ENCTYPE="multipart/form-data" ACTION="http://localhost/scripts/cgiip.exe/WService=wsbroker1/ping" METHOD="POST"> 
<INPUT type="file" name="filename"> 
<INPUT type="submit"> 
</FORM> 
</BODY></HTML>'

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.:
{src/web/method/cgidefs.i}

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:
binaryUploadMaxSize =n
Where:
<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.

Example:
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>



 
Workaround
Notes
Attachment 
Last Modified Date6/21/2016 12:30 PM
Disclaimer

The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.



Feedback
 
Was this article helpful?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful. Please provide us a way to contact you, should we need clarification on the feedback provided or if you need further assistance.

Characters Remaining: 1025