Wiki source code of WOFileUpload
Version 29.1 by Pascal Robert on 2011/04/26 18:15
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{toc}}{{/toc}} | ||
2 | |||
3 | = Introduction = | ||
4 | |||
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>. | ||
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" | ||
9 | |||
10 | For further information on the file upload specification, see RFC1867: http:~/~/www.w3.org/RT/REC-html32.html#rfc1867. | ||
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 | {{code}} | ||
15 | |||
16 | public java.lang.Object formValueForKey(java.lang.String aKey) | ||
17 | |||
18 | {{/code}} | ||
19 | |||
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. | ||
21 | |||
22 | = Usage = | ||
23 | |||
24 | {{code}} | ||
25 | |||
26 | WOFileUpload { filePath=aPath; data=fileData; [inputStream=fileName]; [bufferSize=sizeKB]; [outputStream=fileName]; [streamToFilePath=filePath]; [overwrite=[boolean]]; [finalFilePath=filePath];} | ||
27 | |||
28 | {{/code}} | ||
29 | |||
30 | = Bindings = | ||
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). | ||
40 | |||
41 | = Examples = |