Used in projects
Commons-fileupload-1.2.1.jar
Upload a large file.
Test a piece, the effect is very good.
Summarized as follows:
-
Must set the maximum threshold for uploading files
final Long max_size = ten * 1024x768 * 1024x768 * +//Set upload file up to 10g
-
Must set a temporary directory on the file upload server
//File Upload parameter configuration
//Create a new file upload handle
diskfileitemfactory Factory = new Diskfileitemfactory ();
//Set memory buffer, more than after write temporary file
Factory.setsizethreshold (4096);
//Set up a temporary directory for files uploaded to the server--very important to prevent the system disk from being stored in the system disk for less space
factory.setrepository (New File ("F:\\uploadfiletemp"));
Servletfileupload upload = new Servletfileupload (factory);
upload.setheaderencoding ("Utf-8");
//Set maximum upload value for individual files
Upload.setsizemax (max_size); //File upload limit 10G
-
Make sure to delete temporary directory temporary files after uploading successfully
fileitem.delete (); //Make sure to call, after the file upload is complete, delete the temp directory file ...
-
It is best to record the time at which the file is uploaded from the beginning to the end of the upload, which is useful for analysis of future file upload times
In addition, because the STRUTS2 upload function also introduced the package, but did the interceptor limit file maximum upload size of 2M, you can modify its configuration file to dynamically change the size of the uploaded file, and struts will help you delete the temporary files after the file upload is successful.
I use spring MVC here, need to specify the maximum upload file size in the upload class, (this thing is not dynamically set, the maximum upload file size is generally the system standard, is to let users follow the drop), and must be uploaded after the successful deletion of temporary files.
Use of the Diskfileitemfactory class