Class: HTTP::FormData::Part

Inherits:
Object
  • Object
show all
Includes:
Readable
Defined in:
lib/http/form_data/part.rb

Overview

Represents a body part of multipart/form-data request.

Examples:

Usage with String


body = "Message"
FormData::Part.new body, :content_type => 'foobar.txt; charset="UTF-8"'

Direct Known Subclasses

File

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Readable

#read, #rewind, #size, #to_s

Constructor Details

#initialize(body, content_type: nil, filename: nil) ⇒ Part

Returns a new instance of Part.

Parameters:

  • body (#to_s)
  • content_type (String) (defaults to: nil)

    Value of Content-Type header

  • filename (String) (defaults to: nil)

    Value of filename parameter



23
24
25
26
27
# File 'lib/http/form_data/part.rb', line 23

def initialize(body, content_type: nil, filename: nil)
  @io = StringIO.new(body.to_s)
  @content_type = content_type
  @filename = filename
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



18
19
20
# File 'lib/http/form_data/part.rb', line 18

def content_type
  @content_type
end

#filenameObject (readonly)

Returns the value of attribute filename.



18
19
20
# File 'lib/http/form_data/part.rb', line 18

def filename
  @filename
end