Class: HTTP::FormData::Multipart

### Home Classes Methods

### In Files

- lib/http/form_data/multipart.rb
- lib/http/form_data/multipart/param.rb

### Parent

Object

### Namespace

- CLASS HTTP::FormData::Multipart::Param

### Methods

- ::new
- #content_length
- #content_type
- #to_s

### Class/Module Index

Quicksearch

- HTTP
- HTTP::FormData
- HTTP::FormData::Error
- HTTP::FormData::File
- HTTP::FormData::Multipart
- HTTP::FormData::Multipart::Param
- HTTP::FormData::Urlencoded

No matching classes.

# HTTP::FormData::Multipart

`multipart/form-data` form data.

### Public Class Methods

new(data) click to toggle source

@param [to_h, Hash] data form data key-value Hash

    # File lib/http/form_data/multipart.rb, line 12
    def initialize(data)
      @parts          = Param.coerce FormData.ensure_hash data
      @boundary       = ("-" * 21) << SecureRandom.hex(21)
      @content_length = nil
    end

### Public Instance Methods

content_length() click to toggle source

Returns form data content size to be used for HTTP request `Content-Length` header.

@return [Fixnum]

    # File lib/http/form_data/multipart.rb, line 36
    def content_length
      unless @content_length
        @content_length  = head.bytesize + tail.bytesize
        @content_length += @parts.map(&:size).reduce(:+)
        @content_length += (glue.bytesize * (@parts.count - 1))
      end

      @content_length
    end

content_type() click to toggle source

Returns MIME type to be used for HTTP request `Content-Type` header.

@return [String]

    # File lib/http/form_data/multipart.rb, line 28
    def content_type
      "multipart/form-data; boundary=#{@boundary}"
    end

to_s() click to toggle source

Returns content to be used for HTTP request body.

@return [String]

    # File lib/http/form_data/multipart.rb, line 21
    def to_s
      head + @parts.map(&:to_s).join(glue) + tail
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.