drogon/examples/simple_example/api_Attachment.cc

31 lines
954 B
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
void Attachment::get(const HttpRequestPtr& req,
2018-10-02 12:02:43 +00:00
const std::function<void (const HttpResponsePtr &)>&callback)
2018-09-07 01:53:37 +00:00
{
auto resp=HttpResponse::newHttpViewResponse("FileUpload",HttpViewData());
callback(resp);
}
void Attachment::upload(const HttpRequestPtr& req,
2018-10-02 12:02:43 +00:00
const std::function<void (const HttpResponsePtr &)>&callback)
2018-09-07 01:53:37 +00:00
{
FileUpload fileUpload;
fileUpload.parse(req);
auto files=fileUpload.getFiles();
for(auto file:files)
{
LOG_DEBUG<<"file:"
<<file.getFileName()
<<"(len="
<<file.fileLength()
<<",md5="
<<file.getMd5()
<<")";
file.save("./");
}
auto resp=HttpResponse::newHttpResponse();
resp->setStatusCode(HttpResponse::k200OK);
callback(resp);
}