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();
|
2019-01-21 09:32:49 +00:00
|
|
|
for (auto const &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-11-30 09:34:02 +00:00
|
|
|
file.save("..");
|
|
|
|
file.save(".xx");
|
|
|
|
file.saveAs("../xxx");
|
2018-09-07 01:53:37 +00:00
|
|
|
}
|
2018-10-14 07:56:54 +00:00
|
|
|
auto resp = HttpResponse::newHttpResponse();
|
2019-01-22 15:00:14 +00:00
|
|
|
resp->setStatusCode(k200OK);
|
2018-09-07 01:53:37 +00:00
|
|
|
callback(resp);
|
2018-11-16 05:26:14 +00:00
|
|
|
}
|