Uploading a file using CHttpFile
-
Hi I'm uploading a file using CInternetSession, CHttpConnection and CHttpFile. The program is working properly. However, I have some questions: 1. Does the program send data each time CHttpFile::Write() called? Or are all data sent when CHttpFile::EndRequest() called? 2. How big should the buffer size be(while reading from local file and writing to CHttpFile)?[Please see the source code below] 3. Does using Keep-alive connection(INTERNET_FLAG_KEEP_CONNECTION) help in any way?[Please see the source code below]
CInternetSession ises = NULL;
CHttpFile* httpf = NULL;
CHttpConnection *connection = NULL;file=new CFile(L"file2upload.txt",CFile::modeRead);
connection = ises.GetHttpConnection(L"myserver.com");
http = connection->OpenRequest(CHttpConnection::HTTP_VERB_POST, L"upload.php",0,1,0,0,INTERNET_FLAG_KEEP_CONNECTION);
CString hdrs /* = My appropriate headers to send */;
httpf->AddRequestHeaders(hdrs);PreFileData /* = prefile data */;
PostFileData /* = postfile data */;httpf->SendRequestEx(DWORD(PreFileData.GetLength()+file->GetLength()+PostFileData.GetLength()), HSR_SYNC | HSR_INITIATE);
httpf->Write((LPSTR)(LPCSTR)PreFileData, PreFileData.GetLength());
UINT len=1024;
char buf[1024]; /*BUFFER SIZE = 1024 HOW BIG ACTUALLY SHOULD IT BE?*/
while(len>0){
len=f->Read(&buf,1024);
if(len>0)httpf->Write(&buf,len);
}httpf->Write((LPSTR)(LPCSTR)PostFileData, PostFileData.GetLength());
httpf->EndRequest(HSR_SYNC);
file->Close();
httpf->Close();
connection->Close();Thanks in advance