|Upload - Form parser and VBA 6|
Option Explicit 'Sample of using FormParser class of ASP Huge Upload object 'in VBA 6 Dim Request As ASPTypeLibrary.Request Dim Response As ASPTypeLibrary.Response 'Proces source data stream by blocks Private Sub ProcessRequest(Request As ASPTypeLibrary.Request, Boundary As String, ByVal TotalBytes As Long) Const BlockSize As Long = 1024 Dim BinaryData() As Byte, BlockCounter As Long Dim ReadSize As Long Dim Parser As New ASPHugeUpload.FormParser 'Set form type Parser.FormType = ftMultipart 'Set boundary to form parser Parser.Boundary = Boundary 'Process source data For BlockCounter = 0 To TotalBytes Step BlockSize 'ASP Net does not accept reads more than TotalBytes 'from input. We have to read exact number of bytes. If BlockCounter + BlockSize > TotalBytes Then ReadSize = TotalBytes - BlockCounter Else ReadSize = BlockSize End If 'Read binary data. BinaryData = Request.BinaryRead(BlockSize) 'Process the multipart data block Parser.ProcessBlock BinaryData ' Next 'Do something with source files . Dim File As ASPHugeUpload.FormField For Each File In Parser.Items.Files Response.Write "<br>FileName: " & File.FileName & _ ", Size:" & File.Length Next ' End Sub 'OnStartPage Public Sub OnStartPage(SC As ASPTypeLibrary.ScriptingContext) 'Get request/response objects Set Request = SC.Request Set Response = SC.Response 'is this post request? If Request.ServerVariables("REQUEST_METHOD") = "POST" Then 'Are there some bytes in the request? If Request.TotalBytes > 0 Then 'Check content-type. Dim Boundary As String, ContentType As String ContentType = Request.ServerVariables("HTTP_CONTENT_TYPE") If Len(ContentType) > 0 _ And LCase$(Left$(ContentType, 19)) = "multipart/form-data" Then Dim PosBoundary As Long PosBoundary = Instr(1, ContentType, "boundary=", vbTextCompare) If PosBoundary > 0 Then Boundary = Mid$(ContentType, PosBoundary + Len("boundary=")) 'Right multipart/form-data request, process it ProcessRequest Request, Boundary, Request.TotalBytes Else 'If PosBoundary > 0 Then Response.Write "Bad POST request (not multipart or Boundary)." End If 'If PosBoundary > 0 Then Else 'If Len(ContentType) > 0 Then Response.Write "Content-type header not specified." End If 'If Len(ContentType) > 0 Then Else 'If Request.TotalBytes > 0 Then Response.Write "totalbytes is zero" End If 'If Request.TotalBytes > 0 Then Else Response.Write "Request method is not POST." End If 'If Request.ServerVariables("REQUEST_METHOD") = "POST" Then End Sub 'Proces source data stream in one block Private Sub ProcessRequestOneStep(Request As ASPTypeLibrary.Request, Boundary As String, ByVal TotalBytes As Long) Dim Parser As New ASPHugeUpload.FormParser 'Set form type Parser.FormType = ftMultipart 'Set boundary to form parser Parser.Boundary = Boundary 'Process source data Parser.ProcessBlock Request.BinaryRead(TotalBytes) ' End Sub Public Property Get x() As Long x = 1 End Property
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: firstname.lastname@example.org