@@ -30,14 +30,6 @@ public static Map<String, List<FileItem>> getRequestFiles (HttpServletRequest re
3030 // The Javadoc on this factory class doesn't say anything about thread safety. Looking at the source code it
3131 // all looks threadsafe. But also very lightweight to instantiate, so in this code run by multiple threads
3232 // we play it safe and always create a new factory.
33- // Setting a size threshold of 0 causes all files to be written to disk, which allows processing them in a
34- // uniform way in other threads, after the request handler has returned. This does however cause some very
35- // small form fields to be written to disk files. Ideally we'd identify the smallest actual file we'll ever
36- // handle and set the threshold a little higher. The downside is that if a tiny file is actually uploaded even
37- // by accident, our code will not be able to get a file handle for it and fail. Some legitimate files like
38- // Shapefile .prj sidecars can be really small.
39- // If we always saved the FileItems via write() or read them with getInputStream() they would not all need to
40- // be on disk.
4133 try {
4234 ServletFileUpload sfu = new ServletFileUpload ();
4335 return sfu .parseParameterMap (req );
@@ -69,15 +61,12 @@ public static String getFormField(Map<String, List<FileItem>> formFields, String
6961 }
7062 }
7163
72- public static List <File > storeFileItemsAndUnzip (List <FileItem > fileItems ) {
73- return storeFileItemsAndUnzip (fileItems , FileUtils .createScratchDirectory ());
74- }
75-
7664 /**
77- * Convert `FileItem`s into `File`s and move them into the given directory. Automatically unzip files. Return the
78- * list of new `File` handles.
65+ * Convert `FileItem`s into `File`s and move them into a temp directory. Automatically unzip files. Return the list
66+ * of new `File` handles.
7967 */
80- public static List <File > storeFileItemsAndUnzip (List <FileItem > fileItems , File directory ) {
68+ public static List <File > storeFileItemsAndUnzip (List <FileItem > fileItems ) {
69+ File directory = FileUtils .createScratchDirectory ();
8170 List <File > files = new ArrayList <>();
8271 for (FileItem fi : fileItems ) {
8372 File file = storeFileItemInDirectory (fi , directory );
@@ -91,6 +80,9 @@ public static List<File> storeFileItemsAndUnzip(List<FileItem> fileItems, File d
9180 return files ;
9281 }
9382
83+ /**
84+ * Convert `FileItem`s into `File`s and move them into a temporary directory. Return the list of new `File` handles.
85+ */
9486 public static List <File > storeFileItems (List <FileItem > fileItems ) {
9587 File directory = FileUtils .createScratchDirectory ();
9688 List <File > files = new ArrayList <>();
0 commit comments