如何保存poco上传的文件

How to save poco uploaded file

我想使用poco库上传文件

现在我在 istream 变量中有上传的文件,但我不知道如何将它保存到文件中?

这是我的代码,我可以在其中获取文件的长度。

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();


}

现在还有 1 个文件上传到表单中,如果有超过 1 个文件,在 istream 中如何管理?

现在有2天我在搜索和测试不同的方法,但我找不到任何方法,请帮助解决这个问题。

先谢谢你。

取决于#Abhinav 问题on this post:

我们可以这样写保存代码:

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

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


        fout.close();
    }

但不幸的是,如果有多个文件,此代码无法正确捕获,它只能处理一个文件。