Vapor Documentation Beta

Structure Form​Data​Decoder

public struct FormDataDecoder

Decodes Decodable types from 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 FormDataDecoder FormDataDecoder ContentDecoder ContentDecoder FormDataDecoder->ContentDecoder

Conforms To

ContentDecoder

Initializers

init()

public init()

Creates a new FormDataDecoder.

Methods

decode(_:​from:​headers:​)

public func decode<D>(_ decodable: D.Type, from body: ByteBuffer, headers: HTTPHeaders) throws -> D where D: Decodable

decode(_:​from:​boundary:​)

public func decode<D>(_ decodable: D.Type, from data: String, boundary: String) throws -> D where D: Decodable

decode(_:​from:​boundary:​)

public func decode<D>(_ decodable: D.Type, from data: [UInt8], boundary: String) throws -> D where D: Decodable

Decodes a Decodable item from Data using the supplied boundary.

let foo = try FormDataDecoder().decode(Foo.self, from: data, boundary: "123")

Parameters

encodable

Generic Decodable type.

boundary String

Multipart boundary to used in the encoding.

Throws

Any errors decoding the model with Codable or parsing the data.

Returns

An instance of the decoded type D.