You've seen how to upload multiple files and access each of their individual properties,
as well as how to read properties of the file, such as the TotalBytes
of the upload.
There are several properties that can be set as well. One very useful property is
MaxBytes
. MaxBytes
allows you to set a firm limit on the size of the uploaded file, ensuring that malicious
users do not fill up your server's hard disk with huge files.
When you set the MaxBytes
property,
MaxBytes
once and it will apply to all
files in the current upload, limiting each of them to the value that you specify.
The default value of the MaxBytes
property is zero (0). fileUpload.MaxBytes
= 0
When MaxBytes
is set to its default value of zero, there
is no limit on the size of files that can be uploaded.
Set MaxBytes
before referencing any form elements.
MaxBytes
after referencing a form element, by the time the
MaxBytes
property is set, the upload will have been cached. Note: if
you set MaxBytes
after referencing a form element, but before saving
the uploaded files, MaxBytes
will take effect when you save.
In the following example, we use the same simple form used in the first upload :
The Client Code |
---|
<html> |
Here is the response file, formresp.asp:
The Server Code |
---|
<%@ language="vbscript" %> |
In the upload processing script (formresp.asp), MaxBytes
is set to
1000. That means that FileUp will save up to 1000 bytes of each uploaded file. If
you try to upload a file larger than 1000 bytes, notice that only the first 1000
bytes would be written to the hard disk. No error will be raised, indicating that
the file was truncated.
MaxBytes
is Read/Write property, meaning that it is possible
to both set its value and retrieve its value.
Because the MaxBytes setting truncates the file without raising an error, the server
code is set up to display the number of bytes sent by the browser in comparison
to the number of bytes actually saved on the server. This is a comparison between
Request.TotalBytes
and FileUp's TotalBytes
property.
You may have noticed that the total number of bytes transmitted by you is larger
than your original file's size on the client file system. This is normal, since
the browser must add information such as headers and encoding information. Request.TotalBytes
reports the total including the file, encoding information, and other form elements
that may be present.
MaxBytes
property.MaxBytes
does not raise an error when it truncates files.
See also, MaxBytesToCancel.