我正在试图弄清楚如何强制上传到我的应用引擎应用程序的文件的最大大小。我有以下代码,但它似乎不起作用,因为我能够上传一个10mb文件。有什么想法吗?
ServletFileUpload upload = new ServletFileUpload();
upload.setFileSizeMax(5242880);
FileItemIterator iter = null;
try {
iter = upload.getItemIterator(request);
} catch (FileUploadException e) {
System.out.println(1);
e.printStackTrace();
}
// Parse the request
try {
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if (item.isFormField()) {
System.out.println("Form field " + name + " with value "
+ Streams.asString(stream) + " detected.");
} else {
System.out.println("File field " + name + " with file name "
+ item.getName() + " detected.");
// Process the input stream
System.out.println("ct: "+item.getContentType());
}
}
} catch (FileUploadException e) {
System.out.println(2);
// TODO Auto-generated catch block
e.printStackTrace();
}