choxnox
July 22nd, 2007, 06:26 AM
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:
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!
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:
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!