|
Why can't you use the fileSizeMax property?
fileSizeMax limits size of file on disk. I want limit size of FileItem.getString().
It's OK to have 2Gb file on disk, but result of getString() should be limited to 20K. Assuming UTF-32, which is the largest encoding I am aware of, you may set fileSizeMax to 4* stringSizeMax and have an effective limit. Ok, that's not a hard limit, because the user might use a more efficient encoding in terms of space, but that should be fine, IMO.
No, I want to limit data allowed to be loaded into memory.
I want limit files to 200M and limit size of data in memory to 20K, and I want to avoid explicit checking of getSize() each time before calling getString(). Even better, FileItem.get() should throw exception if file is exceeds some parameter. Point is to deny loading large files into memory from FileItem.get() method. Currently, calling of 200M FileItem.get() (or getString()) causes OutOfMemoryError. > Point is to deny loading large files into memory from FileItem.get() method.
> Point is to deny loading large files into memory from FileItem.get() method. That's what DiskFileItemFactory.setThreshold() gives you. It seems, you are not using this property or are setting it to a non-sensible value. setThreshold() causes large files to be written on disk. But after files is saved to disk, calling of FileItem.get() loads that large item into memory:
=== byte[] fileData = new byte[(int) getSize()]; try {
fis = new FileInputStream(dfos.getFile());
fis.read(fileData);
} catch (IOException e) {
fileData = null;
} finally { return fileData; How about using FileItem.getSize()? Or using a custom FileItemFactory that meets your wished?
I think this functionality would be useful to all users. Because almost nobody checks file.getSize() before calling getString(), so almost any site that uses commons-fileupload can be DOSed by uploading big flie into "text" field.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
FileItem.getString(int limitInBytes)
can be added.