'Generic Commit'
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "update_handler.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <drogon/MultiPart.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace simple_object_storage {
|
||||
@@ -32,9 +33,41 @@ void UpdateHandler::handle_update_object(const drogon::HttpRequestPtr& req, std:
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
} else if (contentType.find("multipart/form-data") != std::string::npos ||
|
||||
contentType.find("application/x-www-form-urlencoded") != std::string::npos) {
|
||||
// Handle form data
|
||||
} else if (contentType.find("multipart/form-data") != std::string::npos) {
|
||||
// Handle multipart form data
|
||||
body = nlohmann::json::object();
|
||||
|
||||
// Parse the multipart form data
|
||||
drogon::MultiPartParser formParser;
|
||||
if (formParser.parse(req) != 0) {
|
||||
resp->setStatusCode(drogon::k400BadRequest);
|
||||
nlohmann::json response = {{"result", "error"}, {"error", "Failed to parse multipart data"}};
|
||||
resp->setBody(response.dump());
|
||||
resp->setContentTypeCode(drogon::CT_APPLICATION_JSON);
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
||||
auto ¶meters = formParser.getParameters();
|
||||
|
||||
// Get hash from form data
|
||||
auto hash_it = parameters.find("hash");
|
||||
if (hash_it != parameters.end()) {
|
||||
body["hash"] = hash_it->second;
|
||||
}
|
||||
|
||||
// Parse metadata if present
|
||||
auto meta_it = parameters.find("metadata");
|
||||
if (meta_it != parameters.end()) {
|
||||
try {
|
||||
body["metadata"] = nlohmann::json::parse(meta_it->second);
|
||||
} catch (const nlohmann::json::parse_error& e) {
|
||||
// If parsing as JSON fails, treat it as a string
|
||||
body["metadata"] = meta_it->second;
|
||||
}
|
||||
}
|
||||
} else if (contentType.find("application/x-www-form-urlencoded") != std::string::npos) {
|
||||
// Handle URL-encoded form data
|
||||
body = nlohmann::json::object();
|
||||
const auto& form = req->getParameters();
|
||||
|
||||
|
Reference in New Issue
Block a user