class FormData < Mixed

Inherits from
Mixed: #call
Includes
Escape: #escape_field_name, #unescape_field_name

FormData class for handling multipart/form-data format used in HTTP forms. Extends Mixed to provide specific support for form fields with names and values.

Nested Classes and Modules

class Parser

A configurable parser for multipart/form-data bodies.

class Upload

A file upload yielded while parsing form data.

Definitions

FIELD_SIZE_LIMIT = 2 * 1024 * 1024

The buffered form field size limit.

UPLOAD_SIZE_LIMIT = 128 * 1024 * 1024

The streamed file upload size limit.

TOTAL_SIZE_LIMIT = 256 * 1024 * 1024

The combined size limit for all form fields and file uploads.

def self.mime_type

Returns the MIME type for form data.

Signature

returns String

The MIME type "multipart/form-data".

Implementation

def self.mime_type
	"multipart/form-data"
end

def add_field(name, value, headers = {})

Adds a form field to the multipart form data.

Signature

parameter name String

The field name.

parameter value String

The field value.

parameter headers Hash

Additional headers for the field.

returns StringPart

The created StringPart for the field.

Implementation

def add_field(name, value, headers = {})
	headers = headers.merge(
		"content-disposition" => "form-data; name=\"#{escape_field_name name}\""
	)
	
	StringPart.new(headers, value).tap do |part|
		@parts << part
	end
end