Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Uploading a file using CHttpFile

Uploading a file using CHttpFile

Scheduled Pinned Locked Moved C / C++ / MFC
phpcomhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    msn92
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups