Home Ask Login Register

Developers Planet

Your answer is one click away!

John Kangari February 2016

How to save poco uploaded file

I want to upload file using poco library.

Now I have the uploaded file in the istream variable but I don't know how I can save it to a file?

Here is my code where i can get the length of the file.

void handlePart(const MessageHeader &header, std::istream &stream) {
    _type = header.get("Content-Type", "(unspecified)");

    if (header.has("Content-Disposition")) {

        std::string disp;
        NameValueCollection params;
        MessageHeader::splitParameters(header["Content-Disposition"], disp, params);

        _name = params.get("name", "(unnamed)");
        _fileName = params.get("filename", "(unnamed)");

    CountingInputStream istr(stream);
    NullOutputStream ostr;
    StreamCopier::copyStream(istr, ostr);
    _length = istr.chars();


Also now it's 1 file uploaded in the form if there be more than 1 file how it will be managed in istream?

Now there is 2 days I'm searching and testing different ways but I couldn't find any way, please help to resolve this problem.

Thank you in advanced.


John Kangari February 2016

Depend on #Abhinav question on this post:

We can write save code like this:

if (fileName.length() != 0){

        std::ofstream fout( fileName, std::ios::binary);
        fout << stream.rdbuf() ;


But unfortunately it's working for one file if there is more than one this code can't catch correctly.

Post Status

Asked in February 2016
Viewed 3,911 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life