MultipartBodyPart

public struct MultipartBodyPart : Hashable

Structure representing part in multipart/form-data request. These parts must have valid headers according to RFC-7578. Everything passed to it is converted to InputStream in order to limit memory usage when sending files to a server.

  • Creates a new instance with custom headers and any input stream.

    Declaration

    Swift

    public init(headers: [String : String], inputStream: InputStream)

    Parameters

    headers

    HTTP headers specific for the part, these are not validated locally and must be correct according to RFC-7578.

    inputStream

    Any byte stream.

  • Creates a new instance from key-value or HTTP parameter.

    Declaration

    Swift

    public init(name: String, value: String)

    Parameters

    name

    Name of the parameter used in Content-Disposition header.

    value

    String value of the parameter set as a body.

  • Creates a new instance with custom headers and data as body.

    Declaration

    Swift

    public init(headers: [String : String], data: Data)

    Parameters

    headers

    HTTP headers specific for the part, these are not validated locally and must be correct according to RFC-7578.

    data

    Bytes sent as a part body.

  • Creates a new instance with file URL used to be converted to body.

    Throws

    APIError.multipartStreamCannotBeOpened if stream was not created from the file.

    Declaration

    Swift

    public init(name: String, url: URL) throws

    Parameters

    name

    Name of the parameter used in Content-Disposition header.

    url

    URL to a local file.