Class: HTTP::FormData::File
Overview
Represents file form param.
Constant Summary collapse
- DEFAULT_MIME =
Default MIME type
"application/octet-stream"
Instance Attribute Summary
Attributes inherited from Part
Instance Method Summary collapse
-
#initialize(file_or_io, opts = {}) ⇒ File
constructor
A new instance of File.
-
#size ⇒ Integer
Returns content size.
-
#to_s ⇒ String
Returns content of a file of IO.
Constructor Details
#initialize(file_or_io, opts = {}) ⇒ File
Returns a new instance of File.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/http/form_data/file.rb', line 37 def initialize(file_or_io, opts = {}) opts = FormData.ensure_hash(opts) if opts.key? :mime_type warn "[DEPRECATED] :mime_type option deprecated, use :content_type" opts[:content_type] = opts[:mime_type] end @file_or_io = file_or_io @content_type = opts.fetch(:content_type, DEFAULT_MIME).to_s @filename = opts.fetch :filename do case file_or_io when String then ::File.basename file_or_io when ::File then ::File.basename file_or_io.path else "stream-#{file_or_io.object_id}" end end end |
Instance Method Details
#size ⇒ Integer
Returns content size.
59 60 61 |
# File 'lib/http/form_data/file.rb', line 59 def size with_io(&:size) end |
#to_s ⇒ String
Returns content of a file of IO.
66 67 68 |
# File 'lib/http/form_data/file.rb', line 66 def to_s with_io(&:read) end |