Multipart
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.
}
}Content copied to clipboard
Types
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
Read out the next part of this multipart request, or return null if no more parts are available.