Builds a multipart/form-data message.
require "http" io = IO::Memory.new builder = HTTP::FormData::Builder.new(io, "aA47") builder.field("name", "joe") file = IO::Memory.new("file contents") builder.file("upload", file, HTTP::FormData::FileMetadata.new(filename: "test.txt")) builder.finish io.to_s # => "--aA47\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\njoe\r\n--aA47\r\nContent-Disposition: form-data; name=\"upload\"; filename=\"test.txt\"\r\n\r\nfile contents\r\n--aA47--"
Creates a new FormData::Builder
which writes to io, using the multipart boundary boundary.
Returns a content type header with correct boundary parameter.
Adds a form part with the given name and value.
Adds a form part called name, with data from io as the value.
Finalizes the multipart message, this method must be called before the generated multipart message written to the IO is considered valid.
Reference
Reference
Object
Object
Creates a new FormData::Builder
which writes to io, using the multipart boundary boundary.
Returns a content type header with correct boundary parameter.
builder = HTTP::FormData::Builder.new(io, "a4VF") builder.content_type # => "multipart/form-data; boundary=\"a4VF\""
Adds a form part with the given name and value. Headers can optionally be provided for the form part.
Adds a form part called name, with data from io as the value. Metadata can be provided to add extra metadata about the file to the Content-Disposition header for the form part. Other headers can be added using headers.
Finalizes the multipart message, this method must be called before the generated multipart message written to the IO is considered valid.
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/HTTP/FormData/Builder.html