Wiki source code of WOFileUpload

Version 39.1 by Pascal Robert on 2023/11/13 11:56

Hide last authors
Pascal Robert 37.1 1 {{toc/}}
Kieran Kelleher 8.1 2
3 = Introduction =
4
Pascal Robert 37.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 ([[doc: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 37.1 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
Kieran Kelleher 8.1 49
Pascal Robert 37.1 50 {{code}}
51 NSPathUtilities.lastPathComponent(filePath)
52 {{/code}}
53
54
55 )))
56 |(((
Pascal Robert 39.1 57
Pascal Robert 37.1 58 data
59 )))|(((
60 NSData
61 )))|(((
62 out
63 )))|(((
64 No
65 )))|(((
66 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.
67 )))
68 |(((
69 inputStream
70 )))|(((
71 String
72 )))|(((
73 in
74 )))|(((
75 No
76 )))|(((
77 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.
78 )))
79 |(((
80 bufferSize
81 )))|(((
82 int
83 )))|(((
84 in
85 )))|(((
86 No
87 )))|(((
88 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.
89 )))
90 |(((
91 outputStream
92 )))|(((
93 String
94 )))|(((
95 out
96 )))|(((
97 No
98 )))|(((
99 WebObjects copies the file upload data from the content to the outputStream specified by this attribute.
100 )))
101 |(((
102 streamToFilePath
103 )))|(((
104 String
105 )))|(((
106 in
107 )))|(((
108 No
109 )))|(((
110 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.
111 )))
112 |(((
113 overwrite
114 )))|(((
115 boolean
116 )))|(((
117 in
118 )))|(((
119 No
120 )))|(((
121 When streamToFilePath is specified, this binding determines whether WebObjects should overwrite an existing file. Defaults to false.
122 )))
123 |(((
124 finalFilePath
125 )))|(((
126 String
127 )))|(((
128 out
129 )))|(((
130 No
131 )))|(((
132 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).
133 )))
134
Pascal Robert 31.1 135 = Examples =
136
137 == Java methods ==
138
Pascal Robert 37.1 139 {{code/}}
Kieran Kelleher 8.1 140
Pascal Robert 31.1 141 == WOD-style ==
Kieran Kelleher 8.1 142
Pascal Robert 37.1 143 {{code/}}
Kieran Kelleher 8.1 144
Pascal Robert 31.1 145 == Inline bindings (WOOGNL) ==
146
147 {{code}}
148
149 <wo:form enctype = "multipart/form-data">
Kieran Kelleher 35.1 150
151 <wo:fileUpload streamToFilePath="$streamPathLocation"
152 overwrite="true"
153 filePath="$clientFilePath"
154 finalFilePath="$finalFilePath" />
155
Pascal Robert 31.1 156 </wo:form>
157
158 {{/code}}
Kieran Kelleher 33.1 159
160 = Related documents =
161
Pascal Robert 37.1 162 [[ERXWOFileUpload>>url:http://wocommunity.org/documents/javadoc/wonder/latest/er/extensions/components/_private/ERXWOFileUpload.html||shape="rect"]]
163 [[AjaxFileUpload>>url:http://wocommunity.org/documents/javadoc/wonder/latest/er/ajax/AjaxFileUpload.html||shape="rect"]]
164 [[NSPathUtilities.lastPathComponent>>url:http://wocommunity.org/documents/javadoc/WebObjects/5.4.2/com/webobjects/foundation/NSPathUtilities.html#lastPathComponent(java.lang.String)||shape="rect"]]
165 [[ERAttachment>>doc:ERAttachment Framework]]
Pascal Robert 39.1 166 [[Database vs Filesystem>>doc:documentation.Home.Best Practices.Development-Database vs Filesystem.WebHome]]
Pascal Robert 37.1 167 [[Localization and Internationalization>>doc:Development-Localization and Internationalization]]