Use of the Diskfileitemfactory class

Source: Internet
Author: User

Used in projects

Commons-fileupload-1.2.1.jar

Upload a large file.

Test a piece, the effect is very good.

Summarized as follows:

    1. Must set the maximum threshold for uploading files

      final Long max_size = ten * 1024x768 * 1024x768 * +//Set upload file up to 10g 

    2. 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

    3. 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 ...

    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.