Forum: Ruby max_multipart_length

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Andras H. (Guest)
on 2017-04-22 18:14

In lib/ruby/2.4.0/cgi/core.rb in line 646 there is this:

@@max_multipart_length= 128 * 1024 * 1024

And this seems to be the limit of my file upload to server side. I can
upload a 120 MB file, but cannot upload of a 130 MB size. I've got an

/usr/local/lib/ruby/2.4.0/cgi/core.rb:646:in `initialize_query': too
large multipart data. (StandardError)
        from /usr/local/lib/ruby/2.4.0/cgi/core.rb:852:in `initialize'

My environment is:
OS: Ubuntu Linux 16.04 LTS (64 bit)
Ruby: 2.4.1p111
Web server: Apache 2.4.18-2

I have no other security stuff (modsecurity, evasive etc), but plain

Any idea how I can increase this limit? Thanks.

Ronald F. (Guest)
on 2017-04-24 15:15
Not tested, but maybe this is worth a try:

First, find out which class the variable is defined in. If I'm not
mistaken, this is in module QueryExtension.

Then, after loading (requiring) the module, but before actually using
its methods, do a


Note that this approach is not without risk and we can smell the hack.
For instance, if the module has another variable which depends on the
one you are going to change, i.e. something like

    @@my_funny_valentine = @@max_multipart_lenght * 2

this connection is broken, as the other variable, naturally, is not
being updated accordingly.

Another (safer) possibility would be to make your own, local,
installation of Ruby, and update the value there inside core.rb. This
again has the drawback that this has to be done on every installation of
a new Ruby method.

So, no solution is really nice, but I can't offer anything better.
Andras H. (Guest)
on 2017-04-24 15:18
Hi, I just got the answer now from the IRC channel of Ruby-lang:

mycgi = => 4 * 1024 * 1024 * 1024)
Ronald F. (Guest)
on 2017-04-24 15:29
That's much nicer indeed.....
Andras H. (Guest)
on 2017-04-24 15:29
Thanks anyway.
This topic is locked and can not be replied to.