Consultor Eletrônico



Kbase P160520: How to upload binary file with customized error message using ABL
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   2/19/2010
Status: Unverified

GOAL:

How to upload binary file with customized error message using ABL

GOAL:

How to upload binary file with customized error message using SpeedScript

GOAL:

How to display customized error message with binary upload with WebSpeed?

GOAL:

Can I customize error for binary upload?

FACT(s) (Environment):

All Supported Operating Systems
OpenEdge 10.1x
OpenEdge 10.2x

FIX:

Code example:

You can modify the code to your expectations.

/******************************************************************/

<SCRIPT LANGUAGE="SpeedScript">
define var foo as memptr.
define var cfile as character.
define var binUploadMaxSize as integer.
/* GET method */
if REQUEST_METHOD = "get" THEN

DO:
</SCRIPT>
<FORM ENCTYPE="multipart/form-data"
METHOD="POST">
<input type="text" name="myfield" value="test">
<INPUT type="file" name="filename">
<INPUT type="submit">
</FORM>
<script LANGUAGE="SpeedScript">
END.
/* POST method */
if REQUEST_METHOD = "post" then

DO:
{&OUT} "<b> Posted file: " get-value("filename") "</b><br>" skip.
/* get size of property from properties file for this broker */
binUploadMaxSize = integer(get-config("binaryUploadMaxSize")).
{&OUT} "binUploadMaxSize is " binUploadMaxSize " <BR>".
/* get the data - filename is the name of the field in the form */
foo = get-binary-data("filename").
if foo <> ? THEN

DO:
/* if we got a valid pointer, save data to file */
cfile = get-value("filename").

copy-lob from foo to file cFile no-convert.
/* display the file size */
{&OUT} "File size is " get-size(foo) "<BR>".
/* free memptr */
set-size(foo) = 0.
END.

ELSE DO:
IF binUploadMaxSize = 0 THEN
{&OUT} "Can't use get-binary-data when binUploadMaxSize = 0 <BR>".
ELSE
{&OUT} "ERROR: File is either too big or get-binary-data failed! <BR>" .
END.

END.
</script>

/******************************************************************/