This project is archived and is in readonly mode.
Multipart form with empty file_field submits nil
-
Chris Barnes
- Assigned user set to josh
-
josh
- Milestone cleared.
-
josh
- 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
So, just to clarify, is this something that needs to be changed in Rack, or in the behavior of plugins like Paperclip?
-
deleted
it was not fixed in 2.3RC2
-
Dmitry Polushkin
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
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
fwiw I'd agree that excluding file fields with no upload from params makes more sense than leaving them in and set to nil.
-
josh
Please submit a patch to rack core ASAP!
-
Trevor Turk
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...?
-
Trevor Turk
Cross-posted here:
-
Rob Anderton
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...
-
Trevor Turk
Rob, your patch works for me. Thank you!
-
josh
- State changed from wontfix to open
-
Repository
- State changed from open to resolved
(from [eced3d8c55c1bbae6915d7c6523c341bc682509a]) Update rack to fix multipart uploads with an empty file [#1945 Multipart form with empty file_field submits nil state:resolved] http://github.com/rails/rails/co...
