Wiki source code of WOFileUpload

Version 36.1 by Pascal Robert on 2012/01/30 22:18

Hide last authors
Kieran Kelleher 8.1 1 {{toc}}{{/toc}}
2
3 = Introduction =
4
Pascal Robert 36.1 5 The **WOFileUpload** element allows you to add an <input type=file> HTML element into your form, hence letting your users upload files to your server. This element must be inside an HTML form ([[WOForm]]) element and the //enctype// binding of the form must be set to "multipart/form-data" (see the examples).
Kieran Kelleher 8.1 6
Pascal Robert 36.1 7 Starting with WebObjects 5.2, it is possible to stream file uploads so that the entire file is not stored in memory on the server while being uploaded.
Kieran Kelleher 8.1 8
Pascal Robert 31.1 9 = Usage =
Kieran Kelleher 8.1 10
11 {{code}}
12
Kieran Kelleher 35.1 13 WOFileUpload {
14 filePath=aPath;
15 data=fileData;
16 [inputStream=fileName];
17 [bufferSize=sizeKB];
18 [outputStream=fileName];
19 [streamToFilePath=filePath];
20 [overwrite=[boolean]];
Kieran Kelleher 33.1 21 [finalFilePath=filePath];
22 }
Kieran Kelleher 8.1 23
24 {{/code}}
25
Pascal Robert 31.1 26 = Bindings =
Kieran Kelleher 8.1 27
Pascal Robert 36.1 28 |= Binding Name |= Binding Type |= In/Out |= Required |= Description
29 | filePath | String | in | Yes | 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}}
30 | data | NSData | out | No | 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.
31 | inputStream | String | in | No | The binding will be set to an InputStream that points to the file upload. Note that the input stream points directly to the multipart request body part incoming stream and thus you **must** consume this input stream and close it inside the current request action logic. If you use this binding, you can only have one WOFileUpload element in your form, and it have to be the last element of the form and the form's multipleSubmit attribute must be set to false. Our advice, just use streamToFilePath.
32 | bufferSize | int | in | No | 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.
33 | outputStream | String | out | No | WebObjects copies the file upload data from the content to the outputStream specified by this attribute.
34 | streamToFilePath | String | in | No | 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.
35 | overwrite | boolean | in | No | When streamToFilePath is specified, this binding determines whether WebObjects should overwrite an existing file. Defaults to false.
36 | finalFilePath | String | out | No | 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 37
Pascal Robert 31.1 38 = Examples =
39
40 == Java methods ==
41
Kieran Kelleher 8.1 42 {{code}}
43
44
45 {{/code}}
46
Pascal Robert 31.1 47 == WOD-style ==
Kieran Kelleher 8.1 48
Pascal Robert 31.1 49 {{code}}
Kieran Kelleher 8.1 50
Pascal Robert 31.1 51
52 {{/code}}
53
54 == Inline bindings (WOOGNL) ==
55
56 {{code}}
57
58 <wo:form enctype = "multipart/form-data">
Kieran Kelleher 35.1 59
60 <wo:fileUpload streamToFilePath="$streamPathLocation"
61 overwrite="true"
62 filePath="$clientFilePath"
63 finalFilePath="$finalFilePath" />
64
Pascal Robert 31.1 65 </wo:form>
66
67 {{/code}}
Kieran Kelleher 33.1 68
69 = Related documents =
70
Pascal Robert 36.1 71 [[ERXWOFileUpload>>http://wocommunity.org/documents/javadoc/wonder/latest/er/extensions/components/_private/ERXWOFileUpload.html]]
72 [[AjaxFileUpload>>http://wocommunity.org/documents/javadoc/wonder/latest/er/ajax/AjaxFileUpload.html]]
73 [[NSPathUtilities.lastPathComponent>>http://wocommunity.org/documents/javadoc/WebObjects/5.4.2/com/webobjects/foundation/NSPathUtilities.html#lastPathComponent(java.lang.String)]]
74 [[ERAttachment>>ERAttachment Framework]]
75 [[Database vs Filesystem>>Development-Database vs Filesystem]]
76 [[Localization and Internationalization>>Development-Localization and Internationalization]]