WOFileUpload

Version 28.1 by Pascal Robert on 2011/04/26 18:47

Introduction

The WOFileUpload element allow you to add a <input type=file> HTML element into your form, hence letting your users to upload files to your server. This element must be inside a HTML form (WOForm) element and the enctype binding of the form must be set to "multipart/form-data" (see the examples).

Starting with WebObjects 5.2, it's now possible to stream file uploads so that the entire file is not stored in memory on the server while being uploaded.

Usage


WOFileUpload { filePath=aPath; data=fileData; [inputStream=fileName]; [bufferSize=sizeKB]; [outputStream=fileName]; [streamToFilePath=filePath]; [overwrite=[boolean]]; [finalFilePath=filePath];}

Bindings

 filePath  The name of the file being uploaded, including the full path when the client is on Windows. To get only the name of the file without the full path, you can use NSPathUtilities.lastPathComponent(filePath) 
 data  The file being uploaded will be stored in a NSData object. Please note that the entire file will be in-memory, so beware of out-of-memory errors if users upload large files. 
 inputStream  The file will be streamed to a Java InputStream object that represents the content of the file. If you use that binding, you can only have one WOFileUpload element in your page, and it have to be the last element of the page and the form's multipleSubmit attribute must be set to false. 
 bufferSize  Sets the size (in bytes) of the buffer used by the outputStream and streamToFilePath attributes. The default buffer size is 512KB. There is no reasonable restriction on the buffer size. 
 outputStream  WebObjects copies the file upload data from the content to the outputStream specified by this attribute. 
 streamToFilePath  WebObjects writes the file upload data from the content directly to the file path specified in this attribute. This is an atomic operation---the data is written to a temporary file, which is renamed when the process is complete. 
 overwrite  When streamToFilePath is specified, this binding determines whether WebObjects should overwrite an existing file. Defaults to false. 
 finalFilePath  When streamToFilePath is specified, its value is set to the actual file location (it may differ from the streamToFilePath value if there is a problem renaming the file). 

Examples

Java methods


WOD-style


Inline bindings (WOOGNL)


<wo:form enctype = "multipart/form-data">
<wo:fileUpload streamToFilePath="$streamPathLocation" overwrite="true" filePath="$clientFilePath" finalFilePath="$finalFilePath" />
</wo:form>

Related documents

ERAttachment
Database vs Filesystem
Localization and Internationalization