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-09-07 01:53:37 +00:00
|
|
|
file.save("./");
|
|
|
|
}
|
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);
|
|
|
|
}
|