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 ParserA configurable parser for
multipart/form-databodies.class UploadA 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
nameString The field name.
-
parameter
valueString The field value.
-
parameter
headersHash 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