Wiki source code of WOFileUpload

Last modified by David Holt on 2012/01/30 22:18

Show last authors
1 {{toc/}}
2
3 = Introduction =
4
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 ([[doc:documentation.Home.Development Architecture.Dynamic Elements.WOForm.WebHome]]) element and the //enctype// binding of the form must be set to "multipart/form-data" (see the examples).
6
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.
8
9 = Usage =
10
11 {{code}}
12
13 WOFileUpload {
14 filePath=aPath;
15 data=fileData;
16 [inputStream=fileName];
17 [bufferSize=sizeKB];
18 [outputStream=fileName];
19 [streamToFilePath=filePath];
20 [overwrite=[boolean]];
21 [finalFilePath=filePath];
22 }
23
24 {{/code}}
25
26 = Bindings =
27
28 |=(((
29 Binding Name
30 )))|=(((
31 Binding Type
32 )))|=(((
33 In/Out
34 )))|=(((
35 Required
36 )))|=(((
37 Description
38 )))
39 |(((
40 filePath
41 )))|(((
42 String
43 )))|(((
44 in
45 )))|(((
46 Yes
47 )))|(((
48 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
49
50 {{code}}
51 NSPathUtilities.lastPathComponent(filePath)
52 {{/code}}
53
54
55 )))
56 |(((
57
58
59
60
61
62 data
63 )))|(((
64 NSData
65 )))|(((
66 out
67 )))|(((
68 No
69 )))|(((
70 The file being uploaded will be stored in a [[NSData>>url:http://www.webobjects.me/API/wo542/com/webobjects/foundation/NSData.html||shape="rect"]] object. Please note that the entire file will be in-memory, so beware of out-of-memory errors if users upload large files.
71 )))
72 |(((
73 inputStream
74 )))|(((
75 String
76 )))|(((
77 in
78 )))|(((
79 No
80 )))|(((
81 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.
82 )))
83 |(((
84 bufferSize
85 )))|(((
86 int
87 )))|(((
88 in
89 )))|(((
90 No
91 )))|(((
92 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.
93 )))
94 |(((
95 outputStream
96 )))|(((
97 String
98 )))|(((
99 out
100 )))|(((
101 No
102 )))|(((
103 WebObjects copies the file upload data from the content to the outputStream specified by this attribute.
104 )))
105 |(((
106 streamToFilePath
107 )))|(((
108 String
109 )))|(((
110 in
111 )))|(((
112 No
113 )))|(((
114 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.
115 )))
116 |(((
117 overwrite
118 )))|(((
119 boolean
120 )))|(((
121 in
122 )))|(((
123 No
124 )))|(((
125 When streamToFilePath is specified, this binding determines whether WebObjects should overwrite an existing file. Defaults to false.
126 )))
127 |(((
128 finalFilePath
129 )))|(((
130 String
131 )))|(((
132 out
133 )))|(((
134 No
135 )))|(((
136 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).
137 )))
138
139 = Examples =
140
141 == Java methods ==
142
143 {{code/}}
144
145 == WOD-style ==
146
147 {{code/}}
148
149 == Inline bindings (WOOGNL) ==
150
151 {{code}}
152
153 <wo:form enctype = "multipart/form-data">
154
155 <wo:fileUpload streamToFilePath="$streamPathLocation"
156 overwrite="true"
157 filePath="$clientFilePath"
158 finalFilePath="$finalFilePath" />
159
160 </wo:form>
161
162 {{/code}}
163
164 = Related documents =
165
166 [[ERXWOFileUpload>>url:http://wocommunity.org/documents/javadoc/wonder/latest/er/extensions/components/_private/ERXWOFileUpload.html||shape="rect"]]
167 [[AjaxFileUpload>>url:http://wocommunity.org/documents/javadoc/wonder/latest/er/ajax/AjaxFileUpload.html||shape="rect"]]
168 [[NSPathUtilities.lastPathComponent>>url:http://wocommunity.org/documents/javadoc/WebObjects/5.4.2/com/webobjects/foundation/NSPathUtilities.html#lastPathComponent(java.lang.String)||shape="rect"]]
169 [[ERAttachment>>doc:documentation.Home.Frameworks.ERAttachment Framework.WebHome]]
170 [[Database vs Filesystem>>doc:documentation.Home.Best Practices.Development-Database vs Filesystem.WebHome]]
171 [[Localization and Internationalization>>doc:documentation.Home.Development Architecture.Localization.Development-Localization and Internationalization.WebHome]]