The problem is that in Wt I cannot download a local file from my computer, I can download a file from the Internet, please help me how to solve this problem…
Here is the source code:
#include "headers.h"
std::string readFileToString(const std::string &filePath) {
std::ifstream file(filePath);
std::stringstream buffer;
buffer << file.rdbuf();
return buffer.str();
}
class Application : public Wt::WApplication
{
public:
Application(const Wt::WEnvironment &env);
private:
bool isClicked = true;
};
Application::Application(const Wt::WEnvironment &env) : WApplication(env)
{
this->setTitle("App");
this->doJavaScript(std::async(std::launch::async | std::launch::deferred,
readFileToString,
"D:/web/script.js"
).get());
auto image = this->root()->addWidget(std::make_unique<Wt::WImage>(""));
image->setAttributeValue("src", "icons/image.png");
image->setAttributeValue("alt", "image");
image->setId("main-image");
}
int main(int argc, char **argv)
{
return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env) {
auto app = std::make_unique<Application>(env);
return app;
});
}
It doesn’t load icons/image
image.png:1
Here’s what it says in the browser:
GET http://127.0.0.1:8000/icons/image.png 404 (Not Found)
New contributor
Адам Хатит is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.