Я создал HTTP-сервер с библиотекой Microsoft C ++ Rest SDK aka Casablanca.Я отправляю файл в 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;
}
}
Я хотел обработать свой файл и сохранить его в папке, так чтоно я не могу получить ожидаемый результат, я блокируюсь уже несколько дней.Надеюсь, вы можете помочь мне, спасибо заранее.