c++wt

Wt::WFileUpload File Too Large


I am trying to enable the user to upload multiple large XML and text files for further processing, but WFileUpload isn't allowing anything over 128kb, and I can't figure out a way to override the default setting. Installed wt 3.3.6 on Xubuntu 16.04. Accessing the wthttp server at 0.0.0.0:8080 using mostly default settings in Firefox.

I have looked into the --help settings for the file_dialog executable, and found the option --max-memory-request-size, but changing that doesn't seem to help. I have also edited the /etc/wt/wt_config.xml to change the max-memory-request-size to values higher than 128kb, also to no avail. Based on the output file "file_dialog-output.txt" I can successfully upload a 60kb file, but a 2Mb file fails.

I am building and running the following code as noted in the .hpp file:

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);
}

Any help is much appreciated!

Wt: https://www.webtoolkit.eu/wt

Wt::WFileUpload: https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WFileUpload.html


Solution

  • Solution: increase the parameter max-request-size within wt_config.xml

    Thanks to these resources for the solution:

    https://www.webtoolkit.eu/wt/doc/reference/html/overview.html

    http://redmine.webtoolkit.eu/boards/2/topics/11351?r=11943#message-11943