25
25
public class MultipartConfiguration {
26
26
private boolean deleteTemporaryFiles = true ;
27
27
28
- private MultipartFileUploadPolicy fileUploadPolicy ;
28
+ private MultipartFileUploadPolicy fileUploadPolicy = MultipartFileUploadPolicy . Reject ;
29
29
30
30
private long maxFileSize = 1024 * 1024 ; // 1 Megabyte
31
31
@@ -117,21 +117,49 @@ public boolean isDeleteTemporaryFiles() {
117
117
return deleteTemporaryFiles ;
118
118
}
119
119
120
+ /**
121
+ * Setting this to <code>true</code> will cause the server to delete all temporary files created while processing a multipart stream after
122
+ * the request handler has been invoked.
123
+ * <p>
124
+ * If you set this to <code>false</code> the request handler will need to manage cleanup of these temporary files.
125
+ *
126
+ * @param deleteTemporaryFiles controls if temporary files are deleted by the server.
127
+ * @return This.
128
+ */
120
129
public MultipartConfiguration withDeleteTemporaryFiles (boolean deleteTemporaryFiles ) {
121
130
this .deleteTemporaryFiles = deleteTemporaryFiles ;
122
131
return this ;
123
132
}
124
133
134
+ /**
135
+ * This is the file upload policy for the HTTP server.
136
+ *
137
+ * @param fileUploadPolicy the file upload policy. Cannot be null.
138
+ * @return This.
139
+ */
125
140
public MultipartConfiguration withFileUploadPolicy (MultipartFileUploadPolicy fileUploadPolicy ) {
141
+ Objects .requireNonNull (fileUploadPolicy , "You cannot set the fileUploadPolicy to null" );
126
142
this .fileUploadPolicy = fileUploadPolicy ;
127
143
return this ;
128
144
}
129
145
146
+ /**
147
+ * This is the maximum size for each file found within a multipart stream which may contain one to many files.
148
+ *
149
+ * @param maxFileSize the maximum file size in bytes
150
+ * @return This.
151
+ */
130
152
public MultipartConfiguration withMaxFileSize (long maxFileSize ) {
131
153
this .maxFileSize = maxFileSize ;
132
154
return this ;
133
155
}
134
156
157
+ /**
158
+ * This is the maximum size of the request payload in bytes when reading a multipart stream.
159
+ *
160
+ * @param maxRequestSize the maximum request size in bytes
161
+ * @return This.
162
+ */
135
163
public MultipartConfiguration withMaxRequestSize (long maxRequestSize ) {
136
164
if (maxRequestSize < maxFileSize ) {
137
165
// In practice the maxRequestSize should be more than just one byte larger than maxFileSize, but I am not going to require any specific amount.
@@ -142,21 +170,56 @@ public MultipartConfiguration withMaxRequestSize(long maxRequestSize) {
142
170
return this ;
143
171
}
144
172
173
+ /**
174
+ * @param multipartBufferSize the size of the buffer used to parse a multipart stream.
175
+ * @return This.
176
+ */
145
177
public MultipartConfiguration withMultipartBufferSize (int multipartBufferSize ) {
178
+ if (multipartBufferSize <= 0 ) {
179
+ throw new IllegalArgumentException ("The multipart buffer size must be greater than 0" );
180
+ }
181
+
146
182
this .multipartBufferSize = multipartBufferSize ;
147
183
return this ;
148
184
}
149
185
186
+ /**
187
+ * A temporary file location used for creating temporary files.
188
+ * <p>
189
+ * The specific behavior of creating temporary files will be dependant upon the {@link MultipartFileManager} implementation.
190
+ *
191
+ * @param temporaryFileLocation the temporary file location. Cannot be <code>null</code>.
192
+ * @return This.
193
+ */
150
194
public MultipartConfiguration withTemporaryFileLocation (String temporaryFileLocation ) {
195
+ Objects .requireNonNull (temporaryFileLocation , "You cannot set the temporaryFileLocation to null" );
151
196
this .temporaryFileLocation = temporaryFileLocation ;
152
197
return this ;
153
198
}
154
199
200
+ /**
201
+ * An optional filename prefix used for naming temporary files.
202
+ * <p>
203
+ * This parameter may be set to <code>null</code>. When set to <code>null</code> a system default such as '.tmp' may be used when naming a
204
+ * temporary file depending upon the {@link MultipartFileManager} implementation.
205
+ *
206
+ * @param temporaryFilenamePrefix an optional filename prefix to be used when creating temporary files.
207
+ * @return This.
208
+ */
155
209
public MultipartConfiguration withTemporaryFilenamePrefix (String temporaryFilenamePrefix ) {
156
210
this .temporaryFilenamePrefix = temporaryFilenamePrefix ;
157
211
return this ;
158
212
}
159
213
214
+ /**
215
+ * An optional filename suffix used for naming temporary files.
216
+ * <p>
217
+ * This parameter may be set to <code>null</code>. The specific file naming with or without this optional suffix may be dependant upon the
218
+ * {@link MultipartFileManager} implementation. file depending upon the {@link MultipartFileManager} implementation.
219
+ *
220
+ * @param temporaryFilenameSuffix an optional filename suffix to be used when creating temporary files.
221
+ * @return This.
222
+ */
160
223
public MultipartConfiguration withTemporaryFilenameSuffix (String temporaryFilenameSuffix ) {
161
224
this .temporaryFilenameSuffix = temporaryFilenameSuffix ;
162
225
return this ;
0 commit comments