Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 262
Product
FileUp
Version
2.x, 3.x
Title
HOWTO: Limit the size of the files uploaded
Problem
There may be a time when you need to limit the size of the files that are allowed to be uploaded. There are three options to choose from to limit the size of files. Two are using FileUp properties MaxBytes and MaxBytesToCancel, and the other is using a Client-Side Component.

MaxBytes defines the maximum number of bytes that are written to disk or into the database on a per-file basis. Use this property in conjunction with error handling.

Setting MaxBytesToCancel may reduce the threat of a DoS (Denial of Service) attack on the server. When an upload size hits MaxBytesToCancel, the connection to the server will be terminated, the ASP page will finish executing, and the ASP thread will be freed.

Solution

Please note: FileUp is NOT able to limit the size of files until they are cached on the server.

Options to Limit File Size
  1. Using the MaxBytes Property

    When you set the MaxBytes property (before saving the file!), FileUp will write the number of bytes that you specify to disk and then stop. The file will remain, but will be incomplete.

    You can set MaxBytes once and it will apply to all files in the current upload, limiting each of them to the value that you specify. By default, there is no limit on the size of file to accept. If you have set a limit, and want to remove this limit, set MaxBytes equal to zero (0).

    Please note: The MaxBytes property will not throw an error or alert the user that the file was too large, so you should include a way to handle this situation.

    Here is a sample:
    <%
    '--- Instantiate FileUp
    Set upl = Server.CreateObject("SoftArtisans.FileUp")
    upl.Path = "c:\temp"
    '--- limit the upload size to 10000 bytes
    upl.MaxBytes = 10000
    '--- please be aware that Request.TotalBytes contains
    '--- all data sent in the RequestStream
    If upl.MaxBytes > Request.TotalBytes Then
    '--- Save the file
    upl.Save
    '--- Alert the user that the file has been saved
    Response.Write "Your file has been uploaded successfully."
    Else
    '--- Alert tyhe user that the file is too large
    Response.Write "The file you submitted is too large and was NOT saved.<br>"
    Response.Write "The limit is 10,000 bytes"

    End If

    %>

    For more information regarding this property please read this article: http://support.softartisans.com/docs/safileupdocs/prog_g_limitsize.htm

  2. Using the MaxBytesToCancel Property

    FileUp will abort a file transfer to the server when the size of the transfer reaches the value of MaxBytesToCancel. No data will be written to the server's hard disk, the connection will be terminated, and the browser will display a "Page not found" message. This should be used only for an absolute Maximum, since it kills the connection and does not allow for error handling.

    Sample:
    <%
    '--- Instantiate FileUp
    Set upl = Server.CreateObject("SoftArtisans.FileUp")
    upl.Path = "c:\temp"
    '--- limit the upload size to 1000000 bytes
    upl.MaxBytesToCancel = 1000000
    '--- Save the file
    upl.Save
    '--- Alert the user that the file has been saved
    Response.Write "Your file has been uploaded successfully."
    %>

    For more information regarding MaxBytesToCancel please read this article: http://support.softartisans.com/docs/safileupdocs/prog_ref_fileup_maxbytestocancel.htm

  3. Use Client-Side Components

    You can also use one of our Client-Side components to limit file size on the client before the request is sent to the server. This will free up server resources by having the limitation take place on the client. These products are XFile (ActiveX Object) and JFile (Applet). FileUp is still used on the server for these products. These products also provide several other advantages over using the just the browser to upload files.

    For more information:

    Regarding XFile please see:

    http://support.softartisans.com/docs/saxfiledocs/default.asp

    Regarding JFile:

    http://support.softartisans.com/docs/sajfiledocs/default.asp
Created : 12/1/2002 12:00:00 AM (last modified : 9/24/2002 6:03:03 PM)
Rate this article!
Comments