Upload - Form parser and VBA 6

          Sample for ScriptUtils.FormParser 

Examples
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
  Other links for Upload - Form parser and VBA 6
      Easy to use, hi-performance ASP file upload component with progress bar indicator. Let's you upload multiple files with size up to 2GB to a disk or database along with another form fields. Works with large posts, any character set (including unicode utf-8). Contains one-click multiple files/folders download with on-the-fly compression (Using BinaryWrite/BinaryRead).
      Hi-performance text file logging for ASP/VBScript/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.
       Lets you work with safearray binary data in VBS/JS. It also enables conversion between binary and String data using several code pages. ZLib compress and uncompress functions. Lets you transfer files using compressed stream from a client to server using IE.
      This library also enables calling of some Kernel and Advapi functions (performance, timing, sleep, configuration ...) and enables native work with INI files.


© 1996 – 2005 Motobit Software, help{at}pstruh.cz, help v. 2.16.14