locked
http multipart/form-data, could someone show me how I get the first bit in VB? RRS feed

  • Question

  • User216680051 posted

    Does the http close his protocol only his content it is totally transmitted? "I think that make sense, but it's just to be certain". So to make a upload component I could do a buffer to get, for example, the first 1024 bits and burn into the hd until finish it, right? How could I get this first 1024 bit and store in the server cpu? Does the http module works with web service? I looked into this thread and I got the example that didn't worked and Travis, who made the programing, says in the line workerRequest.GetPreloadedEntityBody that might not work to VS 2005, which is the point that I got stuck with when I'm debugging. So I decided to do a sample version, which just upload the file and don't do anything else. I did this kind of component before but with classic asp and it converted the byte into string, which it's far from the best practice.

     

    Thank you very much.

    Friday, August 3, 2007 6:32 AM

All replies

  • User216680051 posted

    Here is my module as far that I’ve get. If you run this code with a page named “upload.aspx”, you will perceive that only few times you can retrieve the data from the httpWorkerRequest. Does someone know why it’s very unstable?

    Imports Microsoft.VisualBasic
    Imports System.Web
    Imports System.IO
    
    Public Class upload
        Implements IHttpModule
    
        Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
    
        End Sub
    
        Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
    
            AddHandler context.BeginRequest, AddressOf onBeginRequest
    
        End Sub
    
        Public Sub onBeginRequest(ByVal sender As Object, ByVal e As EventArgs)
            Dim httpApp As HttpApplication = sender
            Dim httpContext As HttpContext = httpApp.Context
            Dim request As HttpRequest = httpContext.Request
            Dim response As HttpResponse = httpContext.Response
            Dim provider As IServiceProvider = httpContext.Current
            Dim worker As HttpWorkerRequest = provider.GetService(GetType(HttpWorkerRequest))
            Dim totalSize As Integer
            Dim memory As MemoryStream
            Dim data() As Byte
            Dim bufferSize As Integer = 4096
            Dim position As Integer
            'Dim myFile As File
    
            If (request.RawUrl.EndsWith("upload.aspx") And worker.HasEntityBody) Then
                totalSize = request.ContentLength
                data = worker.GetPreloadedEntityBody
                memory = New MemoryStream(totalSize)
                memory.Write(data, 0, data.Length)
                position = data.Length
                While (position < totalSize)
                    If (position + bufferSize > totalSize) Then
                        bufferSize = totalSize - position
                    End If
                    position += worker.ReadEntityBody(data, bufferSize)
                    memory.Write(data, 0, bufferSize)
                End While
                'myFile.WriteAllBytes("upload\" & request.Files(0).FileName, data)
            End If
    
        End Sub
    
    End Class
    
     

    Thank you very much.

    Wednesday, August 8, 2007 2:05 PM