okhttp / okhttp3 / MultipartBody

MultipartBody

class MultipartBody : RequestBody

An RFC 2387-compliant request body.

Types

Builder

class Builder

Part

class Part

Functions

boundary

fun boundary(): String

contentLength

fun contentLength(): Long

Returns the number of bytes that will be written to sink in a call to writeTo, or -1 if that count is unknown.

contentType

fun contentType(): MediaType

A combination of type and boundary.

part

fun part(index: Int): MultipartBody.Part

parts

fun parts(): List<MultipartBody.Part>

size

fun size(): Int

The number of parts in this multipart body.

type

fun type(): MediaType

writeTo

fun writeTo(sink: BufferedSink): Unit

Writes the content of this request to sink.

Inherited Functions

isDuplex

open fun isDuplex(): Boolean

A duplex request body is special in how it is transmitted on the network and in the API contract between OkHttp and the application.

isOneShot

open fun isOneShot(): Boolean

Returns true if this body expects at most one call to writeTo and can be transmitted at most once. This is typically used when writing the request body is destructive and it is not possible to recreate the request body after it has been sent.

Companion Object Properties

ALTERNATIVE

val ALTERNATIVE: MediaType

The "multipart/alternative" type is syntactically identical to "multipart/mixed", but the semantics are different. In particular, each of the body parts is an "alternative" version of the same information.

DIGEST

val DIGEST: MediaType

This type is syntactically identical to "multipart/mixed", but the semantics are different. In particular, in a digest, the default Content-Type value for a body part is changed from "text/plain" to "message/rfc822".

FORM

val FORM: MediaType

The media-type multipart/form-data follows the rules of all multipart MIME data streams as outlined in RFC 2046. In forms, there are a series of fields to be supplied by the user who fills out the form. Each field has a name. Within a given form, the names are unique.

MIXED

val MIXED: MediaType

The "mixed" subtype of "multipart" is intended for use when the body parts are independent and need to be bundled in a particular order. Any "multipart" subtypes that an implementation does not recognize must be treated as being of subtype "mixed".

PARALLEL

val PARALLEL: MediaType

This type is syntactically identical to "multipart/mixed", but the semantics are different. In particular, in a parallel entity, the order of body parts is not significant.