Kbase P172797: How to determine Content-Type of the file uploaded with WebSpeed
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  03/09/2010 |
|
Status: Unverified
GOAL:
How to determine Content-Type of the file uploaded with WebSpeed
GOAL:
Is there a way to determine content type of the binary file uploaded to WebSpeed ?
FACT(s) (Environment):
All Supported Operating Systems
OpenEdge 10.1x
OpenEdge 10.2x
FIX:
Add the following function in the WebSpeed object:
FUNCTION getFormContentType RETURNS CHARACTER
( /* parameter-definitions */ ) :
/*------------------------------------------------------------------------------
Purpose: extract content-type from web-context:form-input
Notes:
------------------------------------------------------------------------------*/
DEFINE VARIABLE cFormInput AS CHARACTER NO-UNDO.
DEFINE VARIABLE cReturn AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFormError AS CHARACTER NO-UNDO.
DEFINE VARIABLE iStart AS INTEGER NO-UNDO.
IF WEB-CONTEXT:FORM-INPUT = ? THEN
cFormError = "Problem reading form input" .
ELSE
cFormInput = WEB-CONTEXT:FORM-INPUT .
IF LENGTH(cFormError) > 2 THEN RETURN cFormError.
iStart = INDEX(cFormInput, "Content-Type:") .
cReturn = SUBSTRING(cFormInput, iStart + 14 ) .
cReturn = ENTRY(1, cReturn, CHR(13)).
RETURN cReturn. /* Function return value. */
END FUNCTION.
In the WebSpeed object's procedure process-web-request, use the getFormContentType function to obtain Content-Type information:
PROCEDURE process-web-request :
/*------------------------------------------------------------------------------
Purpose: Process the web request.
Parameters: <none>
Notes:
------------------------------------------------------------------------------*/
/*
* Output the MIME header and set up the object as state-less or state-aware.
* This is required if any HTML is to be returned to the browser.
*/
RUN outputHeader.
{&OUT}
"<HTML>":U SKIP
"<HEAD>":U SKIP
"<TITLE> {&FILE-NAME} </TITLE>":U SKIP
"</HEAD>":U SKIP
"<BODY>":U SKIP
'<form method="post" enctype="multipart/form-data">' SKIP
'<input type="file" name="filename">' skip
'<input type="submit" name="ScrAction" value="Upload">' skip
'</form>'
.
IF get-value("ScrAction") = "upload" THEN
DO:
{&OUT} '<li>' get-value("filename") '</li>'.
{&OUT} '<li>' getFormContentType() '</li>'.
END.
/* Output your custom HTML to WEBSTREAM here (using {&OUT}). */
{&OUT}
"</BODY>":U SKIP
"</HTML>":U SKIP .
END PROCEDURE.