Newsgroups : Microsoft : microsoft.public.inetsdk.programming.wininet : 2007 Aug : WinInet API + "POST" request - how to make upload progress bar?

www.cryer.info
Managed Newsgroup Archive

WinInet API + "POST" request - how to make upload progress bar?

Subject:WinInet API + "POST" request - how to make upload progress bar?
Posted by:"chox.nox" (chox.n..@gmail.com)
Date:Tue, 7 Aug 2007 10:31:22

Hi,

I'm using WinInet APIs in async mode to upload files to server using
HTTP protocol and "POST" request. As a matter of fact, I'm trying to
simulate HTML form (multipart data) submit button.

I can successfully send file, but I have problem with making progress
bar while uploading.
Here is code I'm using for sending:

Code:
------------------------------------------------------------------------------------------------------
while (dwReadLength != 0)
{
    DWORD dwBytesSent = 0;
    dwReadLength = fileLocal.Read(pBuffer, dwChunkLength);
    if (dwReadLength != 0)
    {
        if (!InternetWriteFile(hInternetFile, pBuffer, dwReadLength,
&dwBytesWritten))
        {
            if (::GetLastError() != ERROR_IO_PENDING)
            {

strError.Format("CFileHostingHttpUpload::UploadFile::InternetWriteFile(2)
= %d", ::GetLastError());
                return FALSE;
            }
            WaitForSingleObject(hAsyncOp, INFINITE);
        }
        dwTotalRead+=dwBytesWritten;
        pbUpload->SetPos(((double)dwTotalRead/
dwTotalRequestLength)*100);
    }
}
------------------------------------------------------------------------------------------------------

The problem is that my progress bar gets fully "progressed" in about
1-2 seconds, but file uploading is far slower (25kb/s upload speed).
When I track transfer with net sniffer tool I can see that it takes
about 10 seconds to upload 256 kb file, but progress bar gets fill
almost instantly. I've tried about 6-7 different upload "loops" but
all of them are giving almost same result.

InternetStatusCallback gives me this:
------------------------------------------------------------------------------------------------------
11:49:19 - Connected to server.
11:49:19 - Sending request ...
11:49:19 - Request sent: 186 bytes
11:49:19 - Request complete.
11:49:19 - Sending request ...
11:49:19 - Request sent: 86 bytes
11:49:19 - Sending request ...
11:49:19 - Request sent: 4096 bytes
...
... (a lot of same status until the end of upload, no need to paste
them all :))
...
11:49:19 - Sending request ...
11:49:19 - Request sent: 4096 bytes
11:49:19 - Sending request ...
11:49:19 - Request sent: 4096 bytes
11:49:19 - Request complete.
11:49:19 - Sending request ...
11:49:19 - Request sent: 802 bytes
11:49:19 - Sending request ...
11:49:19 - Request sent: 16 bytes
11:49:19 - Receiving response ...
11:49:29 - Response received: 1024 bytes
11:49:29 -
11:49:29 - Request complete.
------------------------------------------------------------------------------------------------------

Does anybody have any kind of solution?

Best Regards and have a nice day!

Replies:

www.cryer.info
Managed Newsgroup Archive