Upload - Monitor and handle upload state/result | ||
Article, Upload - Monitor and handle upload state/result | ||
Member of ScriptUtils.ASPForm |
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 WebServer.SetInfoYou can also use adsutil.vbs administration script to set the value, or directly edit IIS metabase. |
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 = fsCompletted) 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 fsCompletted = 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)." Else hResult = "Another upload problem." End If hResult = "<Font Color=Red>" & hResult & "</Font>" Response.Status = "400 Bad request" ElseIf Form.State = fsCompletted Then 'Completted hResult = "n of form Items:" & Form.Items.Count '..... Process form fields ElseIf Request.QueryString("Action") = "Cancel" Then Notes. 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) |