This project is archived and is in readonly mode.
Multipart form with empty file_field submits nil
Reported by Chris Barnes | February 11th, 2009 @ 07:54 PM
I noticed that posting a multipart form with a blank file_field submits a nil in edge rails. Is this the intended behavior? In rails 2.2 it submitted an empty string.
I'm using the paperclip plugin which ignores the empty string but deletes attachments that are set to nil. With this new behavior, paperclip deletes every attachment on update. If this is the intended behavior for rails 2.3 then I'll submit a ticket on the paperclip project about modifying the plugin to handle nil values a different way.
My rails SHA-1 is 1a2a71333f197e98d1cd7fe380d613cbada4446b
Comments and changes to this ticket
-
Chris Barnes February 23rd, 2009 @ 06:43 PM
- Assigned user set to josh
-
josh February 23rd, 2009 @ 08:06 PM
- Milestone cleared.
-
josh February 24th, 2009 @ 05:47 PM
- State changed from new to wontfix
Yeah, it looks like rack's multipart parser sets it to nil, which is what we are using now. I think the behavior seems correct. If there is a a good reason to have blank uploads set to "", we should get this fixed in rack core.
I'll make a note of it as an API change.
-
PJ Kelly March 5th, 2009 @ 09:01 AM
So, just to clarify, is this something that needs to be changed in Rack, or in the behavior of plugins like Paperclip?
-
Dmitry Polushkin March 11th, 2009 @ 01:13 AM
Yeah, still doing:
params[:hinge].delete(:image) unless params[:hinge][:image]
before
@hinge.update_attributes(params[:hinge])
Should it be fixed in paperclip?
-
Jon Yurek March 12th, 2009 @ 07:12 PM
I don't think "" is a correct value, but setting it to nil is problematic as file fields can't, unlike any other fields, hold a prepopulated value. So while other fields can simply set themselves to themselves, file fields set to nil will overwrite. While I think nil is technically correct in the case of HTML form submission, it's not in the case of acting like an attribute.
Perhaps the best case is for the Rack multipart handler to simply leave the file out of the params if there is no upload, similarly to how unchecked checkboxes are left out.
-
Rob Anderton March 12th, 2009 @ 09:53 PM
fwiw I'd agree that excluding file fields with no upload from params makes more sense than leaving them in and set to nil.
-
Trevor Turk March 13th, 2009 @ 07:08 AM
I'm attaching a patch that sets blank uploads to "" instead of nil. It appears to fix the problems with Paperclip in my testing.
I can't figure out how to ignore the attribute altogether. Maybe somebody else can give it a shot...?
-
Rob Anderton March 13th, 2009 @ 09:18 AM
I've submitted a slightly different patch over on the rack lighthouse that removes the empty file param instead of setting it to nil/blank.
I'll post a note on the rack mailing list too...
-
josh March 13th, 2009 @ 10:08 PM
- State changed from wontfix to open
-
Repository March 13th, 2009 @ 11:14 PM
- State changed from open to resolved
(from [eced3d8c55c1bbae6915d7c6523c341bc682509a]) Update rack to fix multipart uploads with an empty file [#1945 state:resolved] http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1945 Multipart form with empty file_field submits nil (from [eced3d8c55c1bbae6915d7c6523c341bc682509a]) Update ...