14) Set a Maximum Size and allowable MIME type. 

 

back to main index

 

Xload can control what can and cannot be uploaded by the use of certain parameters being set. The two parameters that can be set are a maximum size of an upload and the allowable MIME types that can be uploaded.

 

1.      Size: If no maximum size is set for a particular file upload then the default allowable size for that file upload is 1Gb. If a maximum size is set for a particular upload then this overrides the default value whether it is smaller or larger than the default value. If multiple maximum sizes are set using multiple targets for the file then the lowest maximum size value is used. The code below demonstrates.

 

Default situation whereby the default (1Gb) maximum size is used:

 

 

XloadManager xman = new XloadManager(request);

xman.target("file1", "uploaded");

 

 

 

 

A given maximum size (2048 kb) is used:

 

 

XloadManager xman = new XloadManager(request);

xman.target("file1", "uploaded", 2048);

 

 

 

 

Multiple maximum sizes for a particular upload are given and the lowest (1048kb) is used:

 

 

XloadManager xman = new XloadManager(request);

xman.target("file1", "uploaded", 2048);

xman.target("file1", "uploaded", 1048);

 

 

 

 

where:

request - HttpServletRequest object.

uploaded - directories to upload files to (relative to the web application directory).

file1 - File parameter inside html (or other) form.

 

 

IMPORTANT:-  Please note that the setting of the maximum file size (whether by the default or bespoke value) for a particular file that is uploaded does not affect the maximum file size setting for another file uploaded in the same request.

 

 

2.      MIME type: The default situation is to allow all MIME types to be uploaded. MIME types can be restricted by using a single method of the XloadManager class as follows, which only allows the MIME type application/pdf  to be uploaded for the file parameter file1.

 

 

XloadManager xman = new XloadManager(request);

...

...

xman.setMIMETypes("file1", new String[]{"application/pdf"});

...

...

xman.upload();

 

 

 

where:

request - HttpServletRequest object.

File1 - File parameter inside html (or other) form.

 

 

The setMIMETypes() method can be called as many times as you like for a particular file parameter and each call to the method just adds the array of MIME types to the set of already stored MIME types from previous calls to the method for that file parameter.

 

 

back to main index

top of page

 

 

 

 

 

 

 

© Gubutech(Xload) 2006  (v1.2)