File Upload Timeout Rails/Paperclip

August 9, 2014 2.8k views

I am trying to upload pictures using the paperclip gem and Ruby on Rails. Everything works great except when I try to upload larger files (~5MB), when the application times out.

I've set the unicorn.rb config file to have a timeout of 120, while the production database.yml file also has a timeout of 120,000 milliseconds. I've also restarted unicorn using service unicorn restart. However, even with these updates, the application still times out - in roughly 5 seconds.

The web application is for a very low-traffic webpage, with only one or two people uploading these types of files occasionally. So, I'm not particularly worried about the performance impact that this functionality might have. Does anyone have any idea what other choke point might be triggering a 5 second timeout error like this?

1 Answer

Okay, figured it out thanks to Chrome (I tend to test in Firefox) which granted me a far more lucid error page:

Nginx: 413 Request Entity Too Large Error

Turns out that I needed to update the timeout and max body size for NGINX.
A solution to this is at:

In my case, using console, I:

SSH into the /etc/nginx folder and type into the console

nano nginx.conf

Iniside of the file, I changed

keepalive_time 120;

Inside of the http section, I also added

client_max_body_size 15M`

Then I saved the file and exited back to SSH, where I restarted NGINX via

service nginx restart
service unicorn restart

I'm unsure if restarting unicorn was necessary, but when I do changes like this, I figure it's a good idea to restart the server. In any event, the program is now happy.

Have another answer? Share your knowledge.