Sha256: 282650a98c25f7b3083d34cfaa0916c8f187fff1468780a03bc973e1e749cd8d
Contents?: true
Size: 1.33 KB
Versions: 37
Compression:
Stored size: 1.33 KB
Contents
module ActionDispatch module Http class UploadedFile 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 end def read(*args) @tempfile.read(*args) end def rewind @tempfile.rewind 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 end end module Upload # Convert nested Hash to HashWithIndifferentAccess and replace # file upload hash with UploadedFile objects def normalize_parameters(value) if Hash === value && value.has_key?(:tempfile) UploadedFile.new(value) else super end end private :normalize_parameters end end end
Version data entries
37 entries across 37 versions & 1 rubygems