locked
HttpWorkerRequest & Uploading Files RRS feed

  • Question

  • User871153443 posted
    hi

    (i cannot speak english well, please forgive me.)
    i want to write a file uploader handler with progress bar. i see similar project and i find a class that microsoft hide it in HttpContext. The name

    of this class is HttpWorkerRequest. this class is power and low level for working http request instead HttpRequest. i work with it and face with

    strange problem. the HttpWorkerRequest has a method ReadEntityBody that not work in my project. please see folowing code :

            public void HandlePostedFile(HttpContext context)
            {

        ...

                if (contentType.Contains("multipart/form-data") &&
                    requestType.ToLower().Equals("post") &&
                    context.Request.Files.Count > 0)
                {
                    // Get low level request processor
                    HttpWorkerRequest wRequest = (HttpWorkerRequest)((IServiceProvider)context).GetService(typeof(HttpWorkerRequest));;
                    int intExceptContentLngth = wRequest.GetTotalEntityBodyLength();

                    if (intExceptContentLngth > 0 && wRequest.HasEntityBody())
                    {

            ... Do something for opening temp file

                        preloadBuffer = wRequest.GetPreloadedEntityBody();
                        if (preloadBuffer == null)
                            preloadBuffer = new byte[0];

            ... Write preloadBuffer data to temp file        

                        if (!wRequest.IsEntireEntityBodyIsPreloaded())
                        {
            ...

                            buffer = new byte[preloadBuffer.Length];
                            while ((!cancel) && (0 != intRemainBytes) && wRequest.HasEntityBody())
                            {
            ...
    ***                        intReadBytes = wRequest.ReadEntityBody(buffer, 0, buffer.Length);

            ... Do something        

                                }
                            }
                            ...
                        }
                        ...
                    }
                }
            }

    the code execute correctly to (***) but in (***) line wRequest.ReadEntityBody(buffer, 0, buffer.Length) can not read any thing and obstacle for

    several second and then read 0 byte. my code is similar other handler that work similarity but i'm confused that what is problem !!!
    please help me...

    Tuesday, March 27, 2007 2:16 PM

All replies

  • User-1087479560 posted
    Hi,
    Can you show me your exact code?
    Wednesday, March 28, 2007 3:07 AM