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
-
#close ⇒ void
Closes the underlying IO if it was opened by this instance.
-
#initialize(path_or_io, opts = nil) ⇒ File
constructor
Creates a new File from a path or IO object.
Methods included from Readable
Constructor Details
#initialize(path_or_io, opts = nil) ⇒ File
Creates a new File from a path or IO object
39 40 41 42 43 44 45 46 |
# File 'lib/http/form_data/file.rb', line 39 def initialize(path_or_io, opts = nil) # rubocop:disable Lint/MissingSuper opts = FormData.ensure_hash(opts) @io = make_io(path_or_io) @autoclose = path_or_io.is_a?(String) || path_or_io.is_a?(Pathname) @content_type = opts.fetch(:content_type, DEFAULT_MIME).to_s @filename = opts.fetch(:filename, filename_for(@io)) end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Closes the underlying IO if it was opened by this instance
When the File was created from a String path or Pathname, the underlying file handle is closed. When created from an existing IO object, this is a no-op (the caller is responsible for closing it).
62 63 64 |
# File 'lib/http/form_data/file.rb', line 62 def close @io.close if @autoclose end |