# File Upload fails for large files

**URL:** <https://www.ruby-forum.com/t/file-upload-fails-for-large-files/153691>\
**Category:** Rails\
**Created:** [November 20, 2008, 6:03am UTC](https://www.ruby-forum.com/t/file-upload-fails-for-large-files/153691 "2008-11-20T06:03:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [November 20, 2008, 6:03am UTC](https://www.ruby-forum.com/t/file-upload-fails-for-large-files/153691/1 "2008-11-20T06:03:13Z")

</div>

Hi,  
I am using mongrel with nginx and I am facing problem when I try to  
upload a large file. After googling about this, I came to know that I  
need to configure nginx.conf file by setting ‘client\_max\_body\_size’  
to  
a value of desired maximum file size. I did that but still it does  
not  
seem to work. Files above 200 KB do not get uploaded. I also get a  
weird error about sockets (Given below the nginx.conf file)  
What am I doing wrong? Please help.

My nginx.conf lokos like this:

user postgres ;  
worker\_processes 2;  
error\_log /var/www/webapps/FileSharing/log/error.log notice;  
pid /var/www/webapps/FileSharing/log/nginx.pid;  
events {  
worker\_connections 1024;  
}

http {  
include mime.types;  
default\_type application/octet-stream;  
# no sendfile on OSX uncomment  
#this if your on linux or bsd  
#sendfile on;  
tcp\_nopush on;  
keepalive\_timeout 65;  
tcp\_nodelay on;  
upstream mongrel {  
server 127.0.0.1:4000;  
server 127.0.0.1:4001;  
server 127.0.0.1:4002;  
}  
gzip on;  
gzip\_min\_length 1100;  
gzip\_buffers 4 8k;  
gzip\_types text/plain;  
server {  
listen 80;  
server\_name [something.com](http://something.com);  
access\_log /var/www/webapps/FileSharing/log/access.log;  
error\_log /var/www/webapps/FileSharing/log/error.log;  
root /var/www/webapps/FileSharing/public;  
access\_log on;  
rewrite\_log on;  
#client\_max\_body\_size 1048576k;  
client\_max\_body\_size 1024M;  
client\_body\_buffer\_size 512k;  
client\_header\_buffer\_size 1048576k;  
location /ui  
{  
root /var/www/webapps/FileSharing/public;  
}  
location ~ ^/$ {  
if (-f /index.html){  
rewrite (._) /index.html last;  
}  
proxy\_pass [http://mongrel](http://mongrel);  
}  
location / {  
if (!-f $request\_filename.html) {  
proxy\_pass [http://mongrel](http://mongrel);  
}  
rewrite (._) $1.html last;  
}  
location ~ .html {  
root /Users/ez/nginx/public;  
}  
location ~\* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|  
bz2|  
doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {  
access\_log off;  
expires 30d;  
}  
location / {  
# needed to forward user’s IP address to rails  
proxy\_set\_header X-Real-IP $remote\_addr;  
# needed for HTTPS  
#proxy\_set\_header X\_FORWARDED\_PROTO https;  
#proxy\_set\_header X-Forwarded-For  
$proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_redirect false;  
#proxy\_max\_temp\_file\_size 1048576k;  
proxy\_max\_temp\_file\_size 1024M;  
# If the file exists as a static file serve it directly  
without  
# running all the other rewite tests on it  
if (-f $request\_filename) {  
break;  
}  
# this is the meat of the rails page caching config  
# it adds .html to the end of the url and then checks  
# the filesystem for that file. If it exists, then we  
# rewite the url to have explicit .html on the end  
# and then send it on its way to the next config rule.  
# if there is no file on the fs then it sets all the  
# necessary headers and proxies to our upstream mongrels  
if (-f $request\_filename.html) {  
rewrite (.\*) $1.html break;  
}  
if (!-f $request\_filename) {  
proxy\_pass [http://mongrel](http://mongrel);  
break;  
}  
error\_page 500 502 503 504 /500.html;  
location = /500.html {  
root /var/www/webapps/FileSharing/public;  
}  
}  
}  
}

Error:

Thu Nov 20 10:47:37 +0530 2008: Error reading HTTP body:  
#\<RuntimeError: Socket read returned insufficient data: 5672\>  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
http\_request.rb:107:in `read_socket' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/ http_request.rb:77:in `read\_body’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
http\_request.rb:55:in `initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ mongrel.rb: 149:in `new’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/  
mongrel.rb:  
149:in `process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ mongrel.rb: 285:in `run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/  
mongrel.rb:  
285:in `initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ mongrel.rb: 285:in `new’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/  
mongrel.rb:  
285:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ mongrel.rb: 268:in `initialize’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/  
mongrel.rb:  
268:in `new' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ mongrel.rb: 268:in `run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
configurator.rb:282:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/ configurator.rb:281:in `each’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
configurator.rb:281:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails: 128:in `run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/  
command.rb:212:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281 /usr/local/bin/mongrel_rails:19:in `load’  
/usr/local/bin/mongrel\_rails:19

---

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [November 20, 2008, 12:18pm UTC](https://www.ruby-forum.com/t/file-upload-fails-for-large-files/153691/2 "2008-11-20T12:18:40Z")

</div>

Its fixed.

We were using a Javascript to submit the form that held the file  
field. When we used a submit button instead of the javascript, it all  
started working properly. I wonder whats wrong internally but for now,  
the code is working :-). If you are doing something similar, make sure  
you use a submit button instead of a Javascript that submits the form.

Chirantan

---

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [November 20, 2008, 3:07pm UTC](https://www.ruby-forum.com/t/file-upload-fails-for-large-files/153691/3 "2008-11-20T15:07:28Z")

</div>

> If you are doing something similar, make sure  
> you use a submit button instead of a Javascript that submits the form.

Chirantan, look into the responds\_to\_parent plugin to do it via JS.

[http://sean.treadway.info/responds-to-parent/](http://sean.treadway.info/responds-to-parent/)

---

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [November 20, 2008, 3:59pm UTC](https://www.ruby-forum.com/t/file-upload-fails-for-large-files/153691/4 "2008-11-20T15:59:52Z")

</div>

Oh great. Thanks for this Mark. 🙂
