我正在尝试让用户上传多个大型XML和文本文件以供进一步处理,但WFileUpload不允许超过128kb的任何内容,我无法找到一种方法来覆盖默认设置。在Xubuntu 16.04上安装wt 3.3.6。使用Firefox中的默认设置访问0.0.0.0:8080的wthttp服务器。
我已经查看了file_dialog可执行文件的--help设置,并找到了选项--max-memory-request-size,但是改变它似乎并没有帮助。我还编辑了/etc/wt/wt_config.xml,将max-memory-request-size更改为高于128kb的值,但也无济于事。基于输出文件" file_dialog-output.txt"我可以成功上传60kb文件,但是2Mb文件失败。
我正在构建并运行以下代码,如.hpp文件中所述:
file_dialog.hpp
//Compile
//g++ file_dialog.cpp -o file_dialog -lwt -lwthttp
//Run
//./file_dialog --docroot . --http-address 0.0.0.0 --http-port 8080
//headers
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WFileUpload>
#include <Wt/WPushButton>
#include <Wt/WBreak>
//FileApplication class definition, derived from WApplication
class FileApplication : public Wt::WApplication
{
public:
FileApplication(const Wt::WEnvironment & env);
Wt::WContainerWidget * file_upload_dialog_container_widget;
Wt::WFileUpload * file_upload;
Wt::WPushButton * file_output_button;
std::ofstream fout;
void tooLargeBytes(long long int byte_size_1);
void warningFileTooLarge(void);
void infoFileUploaded(void);
};
file_dialog.cpp
#include "file_dialog.hpp"
//FileApplication constructer class; returns root with widget
FileApplication::FileApplication(const Wt::WEnvironment& env)
: Wt::WApplication(env)
{
setTitle("File Generation");
this->requestTooLarge().connect(this, &FileApplication::tooLargeBytes);
Wt::WContainerWidget * upload_dialog_container_widget = new Wt::WContainerWidget(root());
Wt::WFileUpload * file_upload = new Wt::WFileUpload(upload_dialog_container_widget);
file_upload->setMultiple(true);
new Wt::WBreak(upload_dialog_container_widget);
Wt::WPushButton * file_output_button = new Wt::WPushButton(upload_dialog_container_widget);
file_output_button->setText("Upload");
file_upload->fileTooLarge().connect(this, &FileApplication::warningFileTooLarge);
file_upload->uploaded().connect(this, &FileApplication::infoFileUploaded);
file_output_button->clicked().connect(file_upload, &Wt::WFileUpload::upload);
file_output_button->clicked().connect(file_output_button, &Wt::WPushButton::disable);
}
//Application - File too large
void FileApplication::tooLargeBytes(long long int byte_size_1)
{
std::ofstream fout ("file_dialog-output.txt");
fout << "byte_size_1";
fout << byte_size_1;
fout.close();
}
//File too large
void FileApplication::warningFileTooLarge(void)
{
std::ofstream fout ("file_dialog-output.txt");
fout << "File too large";
fout.close();
}
//File successfully uploaded
void FileApplication::infoFileUploaded(void)
{
std::ofstream fout ("file_dialog-output.txt");
fout << "File uploaded";
fout.close();
}
//Application constructor function
Wt::WApplication * createApplication(const Wt::WEnvironment& env)
{
return new FileApplication(env);
}
//Main function
int main(int argc, char ** argv)
{
return Wt::WRun(argc, argv, &createApplication);
}
非常感谢任何帮助!
Wt:https://www.webtoolkit.eu/wt
Wt :: WFileUpload:https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WFileUpload.html
答案 0 :(得分:2)
解决方案:在wt_config.xml
中增加参数max-request-size感谢这些解决方案的资源:
https://www.webtoolkit.eu/wt/doc/reference/html/overview.html
http://redmine.webtoolkit.eu/boards/2/topics/11351?r=11943#message-11943