Vapor Documentation Beta

Structure Form​Data​Encoder

public struct FormDataEncoder

Encodes Encodable items to multipart/form-data encoded Data.

See RFC#2388 for more information about multipart/form-data encoding.

Seealso MultipartParser for more information about the multipart encoding.

%3 FormDataEncoder FormDataEncoder ContentEncoder ContentEncoder FormDataEncoder->ContentEncoder

Conforms To

ContentEncoder

Initializers

init()

public init()

Creates a new FormDataEncoder.

Methods

encode(_:​to:​headers:​)

public func encode<E>(_ encodable: E, to body: inout ByteBuffer, headers: inout HTTPHeaders) throws where E: Encodable

encode(_:​boundary:​)

public func encode<E>(_ encodable: E, boundary: String) throws -> String where E: Encodable

encode(_:​boundary:​into:​)

public func encode<E>(_ encodable: E, boundary: String, into buffer: inout ByteBuffer) throws where E: Encodable

Encodes an Encodable item to Data using the supplied boundary.

let a = Foo(string: "a", int: 42, double: 3.14, array: [1, 2, 3])
let data = try FormDataEncoder().encode(a, boundary: "123")

Parameters

encodable E

Generic Encodable item.

boundary String

Multipart boundary to use for encoding. This must not appear anywhere in the encoded data.

Throws

Any errors encoding the model with Codable or serializing the data.

Returns

multipart/form-data-encoded Data.