#include <cppcms/application.h>
#include <cppcms/applications_pool.h>
#include <cppcms/service.h>
#include <cppcms/http_response.h>
#include <cppcms/http_file.h>
#include <iostream>
#include "content.h"
using namespace std;
public:
{
}
void main(std::string )
{
content::upload c;
if(request().request_method()=="POST") {
c.info.load(context());
if(c.info.validate()) {
std::string new_name = "latest_image";
if(c.info.image.value()->mime() == "image/png")
new_name += ".png";
else
new_name += ".jpg";
c.info.image.value()->save_to("./uploads/" + new_name);
c.info.clear();
}
}
render("upload",c);
}
};
int main(int argc,char ** argv)
{
try {
app.applications_pool().mount(cppcms::applications_factory<uploader>());
app.run();
}
catch(std::exception const &e) {
cerr<<e.what()<<endl;
}
}