2010-03-28 08:15:02 -04:00
|
|
|
require 'active_support/core_ext/object/blank'
|
|
|
|
|
2010-01-16 07:17:03 -05:00
|
|
|
module ActionDispatch
|
|
|
|
module Http
|
2010-10-04 19:56:45 -04:00
|
|
|
class UploadedFile
|
2010-09-22 20:35:21 -04:00
|
|
|
attr_accessor :original_filename, :content_type, :tempfile, :headers
|
2010-01-16 07:17:03 -05:00
|
|
|
|
2010-09-22 20:35:21 -04:00
|
|
|
def initialize(hash)
|
|
|
|
@original_filename = hash[:filename]
|
|
|
|
@content_type = hash[:type]
|
|
|
|
@headers = hash[:head]
|
2010-10-04 19:56:45 -04:00
|
|
|
@tempfile = hash[:tempfile]
|
2010-10-04 20:08:25 -04:00
|
|
|
raise(ArgumentError, ':tempfile is required') unless @tempfile
|
2010-01-16 07:17:03 -05:00
|
|
|
end
|
2010-09-22 20:35:21 -04:00
|
|
|
|
2010-10-04 19:56:45 -04:00
|
|
|
def method_missing(name, *args, &block)
|
|
|
|
@tempfile.send(name, *args, &block)
|
|
|
|
end
|
2010-01-16 07:17:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
module Upload
|
2010-06-11 06:15:34 -04:00
|
|
|
# Convert nested Hash to HashWithIndifferentAccess and replace
|
|
|
|
# file upload hash with UploadedFile objects
|
2010-01-16 07:17:03 -05:00
|
|
|
def normalize_parameters(value)
|
|
|
|
if Hash === value && value.has_key?(:tempfile)
|
2010-09-22 20:35:21 -04:00
|
|
|
UploadedFile.new(value)
|
2010-01-16 07:17:03 -05:00
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
private :normalize_parameters
|
|
|
|
end
|
|
|
|
end
|
2010-09-22 20:35:21 -04:00
|
|
|
end
|