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
|
|
|
{
|
2019-01-27 07:59:56 +00:00
|
|
|
MultiPartParser fileUpload;
|
|
|
|
if(fileUpload.parse(req)==0)
|
2018-09-07 01:53:37 +00:00
|
|
|
{
|
2019-01-27 07:59:56 +00:00
|
|
|
auto files = fileUpload.getFiles();
|
|
|
|
for (auto const &file : files)
|
|
|
|
{
|
|
|
|
LOG_DEBUG << "file:"
|
|
|
|
<< file.getFileName()
|
|
|
|
<< "(len="
|
|
|
|
<< file.fileLength()
|
|
|
|
<< ",md5="
|
|
|
|
<< file.getMd5()
|
|
|
|
<< ")";
|
|
|
|
file.save();
|
|
|
|
file.save("123");
|
|
|
|
file.saveAs("456/hehe");
|
|
|
|
file.saveAs("456/7/8/9/" + file.getMd5());
|
|
|
|
file.save("..");
|
|
|
|
file.save(".xx");
|
|
|
|
file.saveAs("../xxx");
|
|
|
|
}
|
|
|
|
Json::Value json;
|
|
|
|
json["result"] = "ok";
|
|
|
|
auto resp = HttpResponse::newHttpJsonResponse(json);
|
|
|
|
callback(resp);
|
|
|
|
return;
|
2018-09-07 01:53:37 +00:00
|
|
|
}
|
2019-01-27 07:59:56 +00:00
|
|
|
Json::Value json;
|
|
|
|
json["result"] = "failed";
|
|
|
|
auto resp = HttpResponse::newHttpJsonResponse(json);
|
2018-09-07 01:53:37 +00:00
|
|
|
callback(resp);
|
2018-11-16 05:26:14 +00:00
|
|
|
}
|