如何保存 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 个文件,如果有多个文件 如何在 istream 中管理它?
现在有 2 天我正在寻找和测试不同的方法,但我找不到任何方法,请帮助解决此问题。
提前谢谢你。
取决于这篇文章 #Abhinav 问题:
我们可以像这样编写保存代码:
if (fileName.length() != 0){
std::ofstream fout( fileName, std::ios::binary);
fileList.push_back(fileName);
fout << stream.rdbuf() ;
fout.close();
}
但不幸的是,如果有多个文件,则此代码无法正确捕获,则它适用于一个文件。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 使用 Poco::Zip 将文件附加到现有 zip 文件
- 如何使用 Poco::ZIP 压缩/解压缩 zip 文件
- 如何静态链接到 POCO C++ so 文件
- 通过HTTPS从POCO StreamCopier获取文件下载进度
- 无法打开输入文件 Poco.obj 或查找 PocoFoundationd.lib
- 如何使用 POCO 库将更改写入".ini"文件?
- POCO - 属性文件配置保存方法始终使用 ":" 作为分隔符进行写入
- Poco C++中的lib文件是什么
- Poco cmake 文件和本地库
- 如何保存 poco 上传的文件
- 获取带有POCO的服务可执行文件文件夹
- 使用POCO上传文件- SSL连接意外关闭异常
- visualgdbc++到RaPi Poco没有这样的文件或目录
- Span Poco日志文件到子目录
- Poco记录器在进程重新启动时不会将日志附加到现有日志文件中