Member variable HttpUploadedFile():Data Foundation

Contains the file content.

Attribute: EXPORTED
Data type: CHARACTER ("")
Description

The member variable :Data contains a character string with the content of the file.

File content can be accessed directly when reading :Data. If the file is stored on disk, the file first is automatically opened and read into memory when :Data is accessed for the first time. If an error occurs when opening or reading the file, the member variable :LastError contains the error code of the file operation. For further details on configuring uploaded file management please refer to the section Global settings in this documentation.

Example:

The following HTML markup implements a file upload from the client to the server. The upload begins when the submit button is pressed and the <CXP/> page upload.cxp is invoked to process the data sent by the client. Note that the methodattribute of the HTML form element must be set to "post", the enctypeattribute must be "multipart/form-data".

<form action="upload.cxp" method="post" enctype="multipart/form-data"> 
   <input type="file"   name="filedata"   /> 
   <input type="submit" name="SubmitButton" /> 
</form> 

The following code fragment illustrates processing of the uploaded file in the <CXP/> page upload.cxp. In the example, the file content is stored in a database:

<% 
IF 0 != ::HttpRequest:Files:NumItems 
   oHttpUploadedFile := ::HttpRequest:Files:filedata 
   cData := oHttpUploadedFile:Data 
   IF oHttpUploadedFile:LastError == 0 
      FILESTORE->CONTENT := cData 
      ? "<h1>File was stored to database</h1>" 
   ELSE 
      ? "<h1>Error oHttpUploadedFile:LastError</h1>" 
      ? "<b>ErrorMessage:</b>" 
      ? "<p>" 
      ? DosErrorMessage(oHttpUploadedFile:LastError) 
      ? "</p>" 
   ENDIF 
ENDIF 
%> 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.