【问题标题】:Get image file from a client request从客户端请求中获取图像文件
【发布时间】:2021-11-16 06:05:19
【问题描述】:

我想通过 HTTP 请求获取 .bmp 格式的图像。当我通过 Postman 发送测试请求时,会添加诸如 Content-Type 之类的标题,当请求保存到流时,它们会自动添加到生成的 .bmp 文件中,并且文件无法正常工作。当我在 Nano 中手动删除不需要的标题时,图像可以按我预期的方式打开。

cpprestsdk有没有办法不加标题,只发图片文件或者标题需要删除?

void Service::handlePost(http_request request)
{
auto fileStream = std::make_sharde<Concurrency::streams::ostream>();
utility::string_t file = "file.bmp";

// open stream to output file
*fileStream = Concurrency::streams::fstream::open_stream(file).get();
request.body().read_to_end(fileStream->streambuf()).wait();
fileStream.close();
//...
}
------------------------------553993878653478454105895
Content-Disposition: form-data; name="image"; filename="file.bmp"
Content-Type: image/bmp

BM /^@^@^@^@^@^@^@^@
(BMP binary file)
^@^@^@^@^@^@^@
------------------------------553993878653478454105895--

【问题讨论】:

    标签: c++ visual-studio rest vspackage cpprest-sdk


    【解决方案1】:

    根据文档(https://github.com/Microsoft/cpprestsdk/wiki/Getting-Started-Tutorial),没有这样的方法,所以你应该自己删除标题。

    【讨论】:

      猜你喜欢
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多