Fixing multipart POST in Rails
Posted by Guy Naor Tue, 30 May 2006 19:31:00 GMT
Our API is REST based, and so we need all the REST verbs to work. Unfortunately Rails doesn't work correctly with multipart PUT submits. The fix is very simple, and it's a one line change in the file actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb:
--- actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb (revision 4380)
+++ actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb (working copy)
@@ -15,7 +15,7 @@
method = :get
end
- if method == :post && (boundary = multipart_form_boundary)
+ if ((method == :post) || (method == :put)) && (boundary = multipart_form_boundary)
@multipart = true
@params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
elseThe only change is adding the :put method to the if that makes the params into multiparams.
I'm posting this as a bug with the patch and the related tests to the Rail trac. Hopefuly it'll be included in a coming release of Rails.


















http://dev.rubyonrails.org/changeset/4388
Thanks Guy!