File Uploading using POCO

Hey all,
I have been working on some old code to get files to upload using POCO. Arturo posted awhile back ofxHttpUtils, for some reason this is not working and I can’t figure out why…

here is some basic code to upload files, I hard coded some form parts.

  
string submitForm(string action) {  
          
        try {  
              
            URI uri( action.c_str() );  
            std::string path(uri.getPathAndQuery());  
          
            if (path.empty()) path = "/";  
              
            HTTPClientSession session(uri.getHost(), uri.getPort());  
            HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);  
              
            HTMLForm form;  
            form.setEncoding(HTMLForm::ENCODING_MULTIPART);  
            form.set("var", "test");  
            form.addPart("image", new FilePartSource(ofToDataPath("test.png", true)));  
              
            form.prepareSubmit(req);  
            std::ostream& send = session.sendRequest(req);  
            form.write(send);  
              
            // get response  
            Poco::Net::HTTPResponse res;  
              
            // print response  
            std::istream &is = session.receiveResponse(res);  
            std::ostringstream stream;  
            Poco::StreamCopier::copyStream(is, stream);  
            return stream.str();  
              
        }catch (Exception& exc){  
              
            return exc.displayText();  
        }  
    }  
  

I read in the documentation that you need to create a Parthandler but was lost from there, I only could find a serverside example. When I go to submit the form, nothing is passed. Any thoughts?

T

I have had success with Roxlu’s ofxCurl, maybe that would work? There is an example with server side code about uploading an image

https://github.com/roxlu/ofxCurl

nick

Yeah I ended up using that, just thought that it would be nice to use POCO since its already in OF. It is a strange bug, can’t figure it out…