我已经使用Microsoft库C ++ Rest SDK(也称为Casablanca)创建了HTTP服务器。 我已将文件发送到api,但找不到如何将其保存到文件夹中。
void handle_uploadPostFile(http_request request)
{
is_authorized(request); //This is just my method for verifying the token
//I tried this:
auto filedata = request.body().read_to_end(buffer).get();
//And tried this:
auto filedata = request.body();
boost::filesystem::path path(boost::filesystem::current_path());
std::string storageFolder{ "\\media" };
std::string repository{ path.string() + storageFolder };
std::ofstream filePath(repository);
filePath << file; //I wanted to create the file by taking the content of my file of my request, but i get all the content of the body request
//I return the content of my request just for testing and debugging
request.reply(200, filedata);
}
int main(int argc, const char** argv)
{
http_listener listenerUpload(L"http://localhost/upload");
listenerUpload.support(methods::POST, handle_uploadPostFile);
try
{
listenerUpload
.open()
.then([&listenerUpload]() {std::TRACE(L"\nstarting to listen uploading file\n"); })
.wait();
while (true);
}
catch (std::exception const & e)
{
std::cout << e.what() << std::endl;
}
}
我想处理我的文件并将其存储到一个文件夹中,所以,但我无法获得预期的结果,因为几天以来我一直处于阻塞状态。 希望您能帮助我,谢谢。