1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.fileupload;
18
19 import java.io.File;
20 import java.util.List;
21
22 import javax.servlet.http.HttpServletRequest;
23
24 /**
25 * <p>High level API for processing file uploads.</p>
26 *
27 * <p>This class handles multiple files per single HTML widget, sent using
28 * {@code multipart/mixed} encoding type, as specified by
29 * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
30 * #parseRequest(HttpServletRequest)} to acquire a list of {@link
31 * org.apache.commons.fileupload.FileItem}s associated with a given HTML
32 * widget.</p>
33 *
34 * <p>Individual parts will be stored in temporary disk storage or in memory,
35 * depending on their size, and will be available as {@link
36 * org.apache.commons.fileupload.FileItem}s.</p>
37 *
38 * @deprecated 1.1 Use {@code ServletFileUpload} together with
39 * {@code DiskFileItemFactory} instead.
40 */
41 @Deprecated
42 public class DiskFileUpload
43 extends FileUploadBase {
44
45 /**
46 * The factory to use to create new form items.
47 */
48 private DefaultFileItemFactory fileItemFactory;
49
50 /**
51 * Constructs an instance of this class which uses the default factory to
52 * create {@code FileItem} instances.
53 *
54 * @see #DiskFileUpload(DefaultFileItemFactory fileItemFactory)
55 * @deprecated 1.1 Use {@code FileUpload} instead.
56 */
57 @Deprecated
58 public DiskFileUpload() {
59 this.fileItemFactory = new DefaultFileItemFactory();
60 }
61
62 /**
63 * Constructs an instance of this class which uses the supplied factory to
64 * create {@code FileItem} instances.
65 *
66 * @see #DiskFileUpload()
67 * @param fileItemFactory The file item factory to use.
68 * @deprecated 1.1 Use {@code FileUpload} instead.
69 */
70 @Deprecated
71 public DiskFileUpload(final DefaultFileItemFactory fileItemFactory) {
72 this.fileItemFactory = fileItemFactory;
73 }
74
75 /**
76 * Returns the factory class used when creating file items.
77 *
78 * @return The factory class for new file items.
79 * @deprecated 1.1 Use {@code FileUpload} instead.
80 */
81 @Override
82 @Deprecated
83 public FileItemFactory getFileItemFactory() {
84 return fileItemFactory;
85 }
86
87 /**
88 * Returns the location used to temporarily store files that are larger
89 * than the configured size threshold.
90 *
91 * @return The path to the temporary file location.
92 * @see #setRepositoryPath(String)
93 * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
94 */
95 @Deprecated
96 public String getRepositoryPath() {
97 return fileItemFactory.getRepository().getPath();
98 }
99
100 /**
101 * Returns the size threshold beyond which files are written directly to
102 * disk.
103 *
104 * @return The size threshold, in bytes.
105 * @see #setSizeThreshold(int)
106 * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
107 */
108 @Deprecated
109 public int getSizeThreshold() {
110 return fileItemFactory.getSizeThreshold();
111 }
112
113 /**
114 * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
115 * compliant {@code multipart/form-data} stream. If files are stored
116 * on disk, the path is given by {@code getRepository()}.
117 *
118 * @param req The servlet request to be parsed. Must be non-null.
119 * @param sizeThreshold The max size in bytes to be stored in memory.
120 * @param sizeMax The maximum allowed upload size, in bytes.
121 * @param path The location where the files should be stored.
122 * @return A list of {@code FileItem} instances parsed from the
123 * request, in the order that they were transmitted.
124 *
125 * @throws FileUploadException if there are problems reading/parsing
126 * the request or storing files.
127 *
128 * @deprecated 1.1 Use {@code ServletFileUpload} instead.
129 */
130 @Deprecated
131 public List<FileItem> parseRequest(final HttpServletRequest req,
132 final int sizeThreshold,
133 final long sizeMax, final String path)
134 throws FileUploadException {
135 setSizeThreshold(sizeThreshold);
136 setSizeMax(sizeMax);
137 setRepositoryPath(path);
138 return parseRequest(req);
139 }
140
141 /**
142 * Sets the factory class to use when creating file items. The factory must
143 * be an instance of {@code DefaultFileItemFactory} or a subclass
144 * thereof, or else a {@code ClassCastException} will be thrown.
145 *
146 * @param fileItemFactory The factory class for new file items.
147 * @deprecated 1.1 Use {@code FileUpload} instead.
148 */
149 @Override
150 @Deprecated
151 public void setFileItemFactory(final FileItemFactory fileItemFactory) {
152 this.fileItemFactory = (DefaultFileItemFactory) fileItemFactory;
153 }
154
155 /**
156 * Sets the location used to temporarily store files that are larger
157 * than the configured size threshold.
158 *
159 * @param repositoryPath The path to the temporary file location.
160 * @see #getRepositoryPath()
161 * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
162 */
163 @Deprecated
164 public void setRepositoryPath(final String repositoryPath) {
165 fileItemFactory.setRepository(new File(repositoryPath));
166 }
167
168 /**
169 * Sets the size threshold beyond which files are written directly to disk.
170 *
171 * @param sizeThreshold The size threshold, in bytes.
172 * @see #getSizeThreshold()
173 * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
174 */
175 @Deprecated
176 public void setSizeThreshold(final int sizeThreshold) {
177 fileItemFactory.setSizeThreshold(sizeThreshold);
178 }
179
180 }