Multipart

interface Multipart(source)

Represents all relevant information associated with a multipart request.

The general shape of processing a multipart request in your API method is like so:

@Api
suspend fun multipart(ctx: ApiContext) {
if (ctx.req.method != HttpMethod.POST) return
val mp = ctx.req.body?.multipart() ?: return

mp.forEachPart { part ->
// Here, part.consumeContent() gives you a ByteSource you can use to stream the content information.
// If you are sure that the content is fairly limited in size, you can use `part.bytes()` or `part.text()`
// instead to read everything directly.

// Also, if you sent file data, you can use
// (part.extras as? Multipart.Extras.File)?.originalFileName
// to get the original file name uploaded by the user.
}
}

Types

Link copied to clipboard
object Companion
Link copied to clipboard
interface Extras

Extra values beyond the common set, provided specifically based the type of part that we are dealing with.

Link copied to clipboard

One section inside the parent Multipart request body.

Functions

Link copied to clipboard
suspend fun Multipart.forEachPart(autoClose: Boolean = true, block: suspend MultipartScope.(Multipart.Part) -> Unit)

A convenience method that wraps Multipart.readNextPart so you don't have to collect it yourself.

Link copied to clipboard
abstract suspend fun readNextPart(): Multipart.Part?

Read out the next part of this multipart request, or return null if no more parts are available.