Changes for page WOFileUpload
Last modified by David Holt on 2012/01/30 22:18
From version 30.1
edited by Pascal Robert
on 2011/04/26 18:15
on 2011/04/26 18:15
Change comment:
There is no comment for this version
To version 31.1
edited by Pascal Robert
on 2011/04/26 18:38
on 2011/04/26 18:38
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -2,40 +2,51 @@ 2 2 3 3 = Introduction = 4 4 5 - AWOFileUpload elementdisplaysa formelement inwhichaclientbrowsercanspecifya filetobeuploadedtotheserver.Itcorrespondsto theHTML:<INPUTtype=file>.5 +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). 6 6 7 -WOFileUpload elements inside of a WOForm require that the WOForm have the attribute's encoding type set as follows: 8 -enctype = "multipart/form-data" 7 +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. 9 9 10 - Forfurther information on the file uploadspecification, seeRFC1867: http:~/~/www.w3.org/RT/REC-html32.html#rfc1867.9 += Usage = 11 11 12 -If you want to process a file upload in a direct action, use WORequest's formValueForKey method to get the contents of the file that has been uploaded. This method is declared as follows: 13 - 14 14 {{code}} 15 15 16 -p ublicjava.lang.Object formValueForKey(java.lang.StringaKey)13 +WOFileUpload { filePath=aPath; data=fileData; [inputStream=fileName]; [bufferSize=sizeKB]; [outputStream=fileName]; [streamToFilePath=filePath]; [overwrite=[boolean]]; [finalFilePath=filePath];} 17 17 18 18 {{/code}} 19 19 20 - InWebObjects 5.2, support for streaming file uploads was added. To support this, these bindingswere added: inputStream; bufferSize; outputStream; streamToFilePath; overwrite; finalFilePath.17 += Bindings = 21 21 22 -= Usage = 19 +| 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 {{code}}NSPathUtilities.lastPathComponent(filePath){{/code}} 20 +| data | The file being uploaded will be stored in a [[NSData>>http://www.webobjects.me/API/wo542/com/webobjects/foundation/NSData.html]] object. Please note that the entire file will be in-memory, so beware of out-of-memory errors if users upload large files. 21 +| 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. 22 +| 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. 23 +| outputStream | WebObjects copies the file upload data from the content to the outputStream specified by this attribute. 24 +| 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. 25 +| overwrite | When streamToFilePath is specified, this binding determines whether WebObjects should overwrite an existing file. Defaults to false. 26 +| 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). 23 23 28 += Examples = 29 + 30 +== Java methods == 31 + 24 24 {{code}} 25 25 26 -WOFileUpload { filePath=aPath; data=fileData; [inputStream=fileName]; [bufferSize=sizeKB]; [outputStream=fileName]; [streamToFilePath=filePath]; [overwrite=[boolean]]; [finalFilePath=filePath];} 27 27 28 28 {{/code}} 29 29 30 -= Bindings =37 +== WOD-style == 31 31 32 -|filePath|The full file path and name of the file uploaded is sent by the browser and returned as a string to the variable or method bound to this attribute. 33 -|data|The file that is uploaded will be returned as an NSData object to the variable or method bound to this attribute. 34 -|inputStream|WebObjects sets this attribute to an InputStream representing the contents of the file upload. This binding can be used only when it is the only WOFileUpload element on the page. Also, within a form with other input elements, it has to be the last element. This implies that the form's multipleSubmit attribute must not be set to true when it contains a WOFileUpload with the InputStream attribute. Otherwise, the WOFileUpload element raises an exception. This attribute is bound by the end of the file content data. 35 -|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. 36 -|outputStream|WebObjects copies the file upload data from the content to the outputStream specified by this attribute. 37 -|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. 38 -|overwrite|When streamToFilePath is specified, this binding determines whether WebObjects should overwrite an existing file. Defaults to false. 39 -|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). 39 +{{code}} 40 40 41 -= Examples = 41 + 42 +{{/code}} 43 + 44 +== Inline bindings (WOOGNL) == 45 + 46 +{{code}} 47 + 48 +<wo:form enctype = "multipart/form-data"> 49 +<wo:fileUpload streamToFilePath="$streamPathLocation" overwrite="true" filePath="$clientFilePath" finalFilePath="$finalFilePath" /> 50 +</wo:form> 51 + 52 +{{/code}}