add upload file
This commit is contained in:
parent
b1887ffeac
commit
f18d7a4bca
@ -160,6 +160,50 @@ namespace trs
|
|||||||
});
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto upload(std::string from, std::string to)
|
||||||
|
{
|
||||||
|
auto r = cpr::Get(cpr::Url(from));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (r.status_code != 200)
|
||||||
|
{
|
||||||
|
hack::exception ex;
|
||||||
|
ex.description("Dont save file, status code not 200");
|
||||||
|
ex.params("from", from);
|
||||||
|
ex.params("to", to);
|
||||||
|
ex.params("status_code", r.status_code);
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream file(to, std::ios::out | std::ios::binary);
|
||||||
|
file.write(r.text.c_str(), r.text.size());
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
catch(hack::exception& ex)
|
||||||
|
{
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
catch(std::exception& e)
|
||||||
|
{
|
||||||
|
hack::exception ex;
|
||||||
|
ex.description("Dont save file");
|
||||||
|
ex.params("from", from);
|
||||||
|
ex.params("to", to);
|
||||||
|
ex.system_error(e);
|
||||||
|
throw ex;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
hack::exception ex;
|
||||||
|
ex.description(var::ALIEN_SYSTEM_ERROR);
|
||||||
|
ex.params("from", from);
|
||||||
|
ex.params("to", to);
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_url;
|
std::string m_url;
|
||||||
|
@ -50,6 +50,8 @@ auto main(int argc, char* args[]) -> int
|
|||||||
auto r2 = cli_2.post("func_name", j);
|
auto r2 = cli_2.post("func_name", j);
|
||||||
hack::log()(r1.text, r2.status_code);
|
hack::log()(r1.text, r2.status_code);
|
||||||
|
|
||||||
|
cli_2.upload("https://file-examples.com/storage/feaf4c715066a139295358c/2017/11/file_example_MP3_700KB.mp3", "/mnt/raid/projects/trs/test.mp3");
|
||||||
|
|
||||||
trs::server srv;
|
trs::server srv;
|
||||||
srv.init("test service");
|
srv.init("test service");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user