-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload path comment does not stand #1964
Comments
To add to this, it seems we can't even alias the uploads folder with {
"app": {
"document_root": "./frontend",
"upload_path": "../confidential/database/uploads",
"locations": [
{
"uri_prefix": "/uploads",
"is_case_sensitive": false,
"is_recursive": true,
"alias": "../confidential/database/uploads",
"filters": [ "UploadsFilter" ]
}
]
}
} We have to create an HTTP controller and do a file response with the uploads path. |
This is the way I had to do it: #include "drogon/HttpAppFramework.h"
#include "drogon/HttpResponse.h"
#include "drogon/utils/FunctionTraits.h"
#include <functional>
#include <iostream>
#include <string>
#include <string_view>
static constexpr std::string_view
uploadsPrefix = "/uploads/",
uploadsPathRegex = "^/uploads/.+";
static_assert(uploadsPathRegex.substr(1).starts_with(uploadsPrefix), "Uploads path and regex must match");
static const std::string uploadsRegex = std::string(uploadsPathRegex);
int main()
{
drogon::app()
.registerHandlerViaRegex(::uploadsRegex,
[](
const drogon::HttpRequestPtr &req,
std::function<void(const drogon::HttpResponsePtr &)> &&callback)
{
std::string_view uploads = drogon::app().getUploadPath();
std::string_view path = req->path();
path.remove_prefix(::uploadsPrefix.size());
std::string file;
file.reserve(uploads.size() + 1 + path.size());
file = uploads;
file += '/';
file += path;
callback(drogon::HttpResponse::newFileResponse(file));
})
.loadConfigFile("./config.json")
.addListener("127.0.0.1", 8080)
.run();
}
{
"app": {
"document_root": "./frontend",
"upload_path": "../confidential/database/uploads"
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
In config.example.json it is stated:
However, if I setup a project where I put a relative path to the running context for both
document_root
andupload_path
:Drogon creates the
uploads
folder within thedocument_root
path,./frontend/confidential/database/uploads
. This contradicts with the statement written as a comment in the example.Expected behavior
Pages should be served in
./frontend
, and uploads should be uploaded to./confidential/database/uploads
.Desktop (please complete the following information):
Additional context
Currently it's possible to achieve the desired result with either
/home/user/project/confidential/database/uploads
or../confidential/database/uploads
.The text was updated successfully, but these errors were encountered: