drogon/examples/simple_example/api_Attachment.cc

35 lines
1.1 KiB
C++
Raw Normal View History

2018-09-07 01:53:37 +00:00
#include "api_Attachment.h"
using namespace api;
//add definition of your processing function here
2018-10-14 07:56:54 +00:00
void Attachment::get(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback)
2018-09-07 01:53:37 +00:00
{
2018-10-14 07:56:54 +00:00
auto resp = HttpResponse::newHttpViewResponse("FileUpload", HttpViewData());
2018-09-07 01:53:37 +00:00
callback(resp);
}
2018-10-14 07:56:54 +00:00
void Attachment::upload(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback)
2018-09-07 01:53:37 +00:00
{
FileUpload fileUpload;
fileUpload.parse(req);
2018-10-14 07:56:54 +00:00
auto files = fileUpload.getFiles();
for (auto file : files)
2018-09-07 01:53:37 +00:00
{
2018-10-14 07:56:54 +00:00
LOG_DEBUG << "file:"
<< file.getFileName()
<< "(len="
<< file.fileLength()
<< ",md5="
<< file.getMd5()
<< ")";
2018-11-26 08:36:57 +00:00
file.save();
file.save("123");
file.saveAs("456/hehe");
file.saveAs("456/7/8/9/"+file.getMd5());
2018-09-07 01:53:37 +00:00
}
2018-10-14 07:56:54 +00:00
auto resp = HttpResponse::newHttpResponse();
2018-09-07 01:53:37 +00:00
resp->setStatusCode(HttpResponse::k200OK);
callback(resp);
2018-11-16 05:26:14 +00:00
}