Upload - Monitor and handle upload state/result Article

Member of  ScriptUtils.ASPForm | Changes | Purchase | Download

Upload - Monitor and handle upload state/result

Monitoring of upload results, problem with UploadReadAheadSize and 'friendly' http error messages from Internet Explorer.

 IIS server and Upload/POST data   
        The POST request comunication between client and server is realized in blocks of data. 
  1. Client sends http header with basic info about POST data - content-type and content-length headers.
  2. IIS will then response 100 Continue http header and will try to read source data from client. 
  3. Client sends form data
  4. IIS reads UploadReadAheadSize bytes first, and the data are passed to ASP BinaryRead. ASP can read reast of data using BinaryRead.

      This IIS concept is a problem to handle errors and limit upload size with large uploads. The problem is mainly with UploadReadAheadSize and 100 Continue IIS message. You have to change UploadReadAheadSize value to zero if you want to control and properly handle fsSizeLimit event. UploadReadAheadSize can be set for whole IIS, web site, virtual dir, folder or file. The basic code to set this value is:
  Dim WebServer, UploadReadAheadSize
'  Set WebServer = GetObject("IIS://localhost/W3SVC[/sitenum[/folder[/uploadscript.asp]]]")
  Set WebServer = GetObject("IIS://localhost/W3SVC/1")
  'Get UploadReadAheadSize property
  UploadReadAheadSize = WebServer.UploadReadAheadSize
  'Set another size
  WebServer.UploadReadAheadSize = 0

    You can also use adsutil.vbs administration script to set the value, or directly edit IIS metabase.
cscript adsutil.vbs SET W3SVC/1/Root/Upload/UploadReadAheadSize 0
    You can set any other response code instead of first 100 Continue with UploadReadAheadSize set to zero. This property has to be set to control form size limit. If a client exceeds form size limit, you can set response.status to "413 Request Entity Too Large" and response.write some explanation message about the problem. Please see more in Cannot find server or DNS Error, page cannot be displayed when uploading files? and UploadReadAheadSize articles.
 Monitor State property   
        Huge-ASP upload lets you monitor several upload states. Main property to monitor upload results and current state is ScriptUtils.ASPForm.State with ScriptUtils.FormStates values. 
       Upload can finish as completed (State = fscompleted) or with some error (State>fsError). There are three usual errors: Form data exceeds size limit, upload time exceeds timeout limit and client was stopped upload.
       There may be also two different states of cancel of upload - With/Without progress bar. Huge-ASP upload progress bar has a special querystring parameter to cancel upload - request.QueryString("Action") = "Cancel", when user clicks "Cancel" button on progress indicator.
       You can see typical code to handle possible upload states bellow:
  Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
  'Do not upload data greater than 20MB.
  Form.SizeLimit = 20*&H100000
  'Set maximum upload time to 10 munutes.
  Server.ScriptTimeout = 10*60
  Const fscompleted  = 0
  Const fsSizeLimit   = &HD
  Const fsTimeOut     = &HE
  Const fsError       = &HA
  Dim hResult
  If Form.State > fsError Then 'Some error state. 
    If Form.State = fsSizeLimit Then 'Data size exceeds limit. 
      hResult = "Form data exceeds limit (" & Form.SizeLimit/1024 & "kB)."
    ElseIf Form.State = fsTimeOut Then 'Request timeout 
      hResult = "Upload time exceeds limit (" & Form.ReadTimeout & "s)."
      hResult = "Another upload problem."
    End If
    hResult = "<Font Color=Red>" & hResult & "</Font>"
    Response.Status = "400 Bad request"
  ElseIf Form.State = fscompleted Then 'completed
    hResult = "n of form Items:" & Form.Items.Count
    '..... Process form fields
  ElseIf Request.QueryString("Action") = "Cancel" Then
  hResult = "Upload was cancelled."
End If %>

      1. Remember that fsZeroLength is a regular state for application/x-www-form-urlencoded forms (application/x-www-form-urlencoded without fields, there is not usual state, of course)
      2. You do not need a special handler for fsNoConnected state - client will not see output message if disconnected.
      3. fsInProgress and fsNone states are designed for HTML progress bar indicator. ASPForm object is true free-threaded class, so you can access object state and form fields from another ASP task. The second task will receive fsNone state before first upload data was received and fsInProgress during upload (see ScriptUtils.ASPForm.Upload - Progress bar indicator)

Other links for Upload - Monitor and handle upload state/result article


Huge ASP upload is easy to use, hi-performance ASP file upload component with progress bar indicator. This component lets you upload multiple files with size up to 4GB to a disk or a database along with another form fields. Huge ASP file upload is a most featured upload component on a market with competitive price and a great performance . The software has also a free version of asp upload with progress, called Pure asp upload , written in plain VBS, without components (so you do not need to install anything on server). This installation package contains also ScriptUtilities library. Script Utilities lets you create hi-performance log files , works with binary data , you can download multiple files with zip/arj compression, work with INI files and much more with the ASP utility.

© 1996 - 2011 Antonin Foller, Motobit Software | About, Contacts | e-mail: info@pstruh.cz

Other Motobit links:   IISTracer, real-time IIS monitor   ASP file upload - upload files to ASP. 
ActiveX/VBSScript registry editor  ActiveX NT User account manager  Export MDB/DBF from ASP Active LogFile  Email export  ActiveX/ASP Scripting Dictionary object