Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails' Paperclip gem POSTing instead of PUTting when uploading .zip file

I've got a form (Rails 3.2.8, Paperclip 3.1.4) with two Paperclip attachments for a model with two has_attached_files. One is meant to be an image, the other a generic file, usually a .zip file.

Everything works fine so long as I don't try to upload a .zip file. Uploading a .zip file of any size (original was 80 MB but tried 3 MB to see if it was a size issue) causes the form to POST instead of PUT and Rails throws a routing error.

The form method is POST but has the Rails' hidden _method value set to 'put', which works fine and does cause a PUT when I'm not trying to upload .zip files.

The form does have the enctype 'multipart' bit set correctly.

Any idea what could be causing this?

like image 530
Christopher Avatar asked Aug 22 '12 19:08

Christopher


1 Answers

The file sounds large. Double check that the actual params are making it into the request. I get this on local as well depending on the size of the files.

The effect I've seen is that rails would basically get no params. Since a PUT is actually a post with a hidden element, rails would see only the POST since params are dropped.

I am actually not sure what is causing this. I think it may be the local webserver, so you may need to configure nginx or something. This never happens to me on heroku or anything, but always on local if the file is big enough.

Also note, webrick has a really really small size of the request payload limitation. So don't use that. Use "thin" as it is a really easy replacement.

like image 50
Dmitriy Likhten Avatar answered Sep 23 '22 03:09

Dmitriy Likhten