diff --git a/src/main.cpp b/src/main.cpp index 8284600..fc06c39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1046,6 +1046,63 @@ int main(int argc, char *argv[]) { }); + CROW_ROUTE(app, "/fileuploadtest") + ([&, configuration](const crow::request& getRequest ) { + auto& cookieCtx = app.get_context(getRequest); + crow::mustache::context ctx; + if (Utilities::checkCookieLoginState(configuration, cookieCtx)) { + + + + + + + ctx[MUSTACHE_COOKIE_LOGGED_IN] = true; + } + auto page = crow::mustache::load("TEST_UPLOAD.html"); + return page.render(ctx); + }); + + + CROW_ROUTE(app, "/fileuploadtestExecution") + .methods(crow::HTTPMethod::Post)([](const crow::request& postRequest) { + crow::multipart::message multipartMessage(postRequest); + for (const auto& part : multipartMessage.part_map) + { + const auto& mustacheSubmissionNameValue = part.first; + const auto& fileSubmission = part.second; + if (MUSTACHE_FREELANCER_SUBMISSION_NAME == mustacheSubmissionNameValue) + { + auto contentDispositionIt = fileSubmission.headers.find("Content-Disposition"); + if (contentDispositionIt == fileSubmission.headers.end()) + { + //ERROR no content disposition found + return crow::response(400); + } + auto filenameIt = contentDispositionIt->second.params.find("filename"); + if (filenameIt == contentDispositionIt->second.params.end()) + { + //ERROR no filename found + return crow::response(400); + } + + const std::string outputFilename = filenameIt->second; + + std::ofstream outputFileStream(outputFilename); + if (!outputFileStream) + { + //ERROR Write to file failed + } + outputFileStream << fileSubmission.body; + outputFileStream.close(); + } + else + { + //ERROR Mustache Submission Name can not be found + } + } + return crow::response(200); + }); diff --git a/src/templateConstCollection.cpp b/src/templateConstCollection.cpp index dd09f68..6a5ed29 100644 --- a/src/templateConstCollection.cpp +++ b/src/templateConstCollection.cpp @@ -86,6 +86,7 @@ namespace TemplateConstCollection { const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_VIEW = "OPERATION_VIEW"; const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_EDIT = "OPERATION_EDIT"; const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_DELETE = "OPERATION_DELETE"; + const static std::string MUSTACHE_FREELANCER_SUBMISSION_NAME = "FILE_SUBMISSION"; //Cookie names const static std::string COOKIE_LOGIN_KEY = "loginKey"; diff --git a/templates/TEST_UPLOAD.html b/templates/TEST_UPLOAD.html new file mode 100644 index 0000000..28da6a3 --- /dev/null +++ b/templates/TEST_UPLOAD.html @@ -0,0 +1,22 @@ + + + + {{> templateIncludes/style.css.html}} + + +
+ +

+
+ +

+

+ +

+
+ + + + + + \ No newline at end of file