diff options
Diffstat (limited to 'actionpack/lib/action_dispatch/http/upload.rb')
| -rw-r--r-- | actionpack/lib/action_dispatch/http/upload.rb | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb index a15ad28f16..ce8c2729e9 100644 --- a/actionpack/lib/action_dispatch/http/upload.rb +++ b/actionpack/lib/action_dispatch/http/upload.rb @@ -4,41 +4,28 @@ module ActionDispatch attr_accessor :original_filename, :content_type, :tempfile, :headers def initialize(hash) - @original_filename = encode_filename(hash[:filename]) - @content_type = hash[:type] - @headers = hash[:head] @tempfile = hash[:tempfile] raise(ArgumentError, ':tempfile is required') unless @tempfile - end - def open - @tempfile.open - end - - def path - @tempfile.path + @original_filename = encode_filename(hash[:filename]) + @content_type = hash[:type] + @headers = hash[:head] end def read(*args) @tempfile.read(*args) end - def rewind - @tempfile.rewind + # Delegate these methods to the tempfile. + [:open, :path, :rewind, :size, :eof?].each do |method| + class_eval "def #{method}; @tempfile.#{method}; end" end - def size - @tempfile.size - end - private + def encode_filename(filename) - # Encode the filename in the utf8 encoding, unless it is nil or we're in 1.8 - if "ruby".encoding_aware? && filename - filename.force_encoding("UTF-8").encode! - else - filename - end + # Encode the filename in the utf8 encoding, unless it is nil + filename.force_encoding("UTF-8").encode! if filename end end |
