Wiki source code of WOFileUpload

Version 29.1 by Pascal Robert on 2011/04/26 18:15

Hide last authors
Kieran Kelleher 8.1 1 {{toc}}{{/toc}}
2
3 = Introduction =
4
Pascal Robert 29.1 5 A WOFileUpload element displays a form element in which a client browser can specify a file to be uploaded to the server. It corresponds to the HTML: <INPUT type=file>.
Kieran Kelleher 8.1 6
Pascal Robert 29.1 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"
Kieran Kelleher 8.1 9
Pascal Robert 29.1 10 For further information on the file upload specification, see RFC1867: http:~/~/www.w3.org/RT/REC-html32.html#rfc1867.
Kieran Kelleher 8.1 11
Pascal Robert 29.1 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
Kieran Kelleher 8.1 14 {{code}}
15
Pascal Robert 29.1 16 public java.lang.Object formValueForKey(java.lang.String aKey)
Kieran Kelleher 8.1 17
18 {{/code}}
19
Pascal Robert 29.1 20 In WebObjects 5.2, support for streaming file uploads was added. To support this, these bindings were added: inputStream; bufferSize; outputStream; streamToFilePath; overwrite; finalFilePath.
Kieran Kelleher 8.1 21
Pascal Robert 29.1 22 = Usage =
Kieran Kelleher 8.1 23
24 {{code}}
25
Pascal Robert 29.1 26 WOFileUpload { filePath=aPath; data=fileData; [inputStream=fileName]; [bufferSize=sizeKB]; [outputStream=fileName]; [streamToFilePath=filePath]; [overwrite=[boolean]]; [finalFilePath=filePath];}
Kieran Kelleher 8.1 27
28 {{/code}}
29
Pascal Robert 29.1 30 = Bindings =
Kieran Kelleher 8.1 31
Pascal Robert 29.1 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).
Kieran Kelleher 8.1 40
Pascal Robert 29.1 41 = Examples =