diff --git a/client-multipart/README.md b/client-multipart/README.md index dec4a12d..54fe4056 100644 --- a/client-multipart/README.md +++ b/client-multipart/README.md @@ -1,6 +1,7 @@ # Client Multipart -A sample project for [Ktor](https://ktor.io) showing how to send [multipart data](https://ktor.io/docs/request.html#upload_file) from the HttpClient. +A sample project for [Ktor](https://ktor.io) showing how to +send [multipart data](https://ktor.io/docs/client-requests.html#upload_file) from the HttpClient. ## Running diff --git a/client-multipart/src/MultipartApp.kt b/client-multipart/src/MultipartApp.kt index 8394545b..101747db 100644 --- a/client-multipart/src/MultipartApp.kt +++ b/client-multipart/src/MultipartApp.kt @@ -5,7 +5,6 @@ import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.http.content.* -import io.ktor.server.application.* import io.ktor.server.engine.* import io.ktor.server.netty.* import io.ktor.server.request.* @@ -13,7 +12,8 @@ import io.ktor.server.response.* import io.ktor.server.routing.* import io.ktor.util.* import io.ktor.utils.io.* -import io.ktor.utils.io.core.* +import io.ktor.utils.io.jvm.javaio.* +import kotlinx.io.readByteArray import java.util.* fun main() { @@ -41,11 +41,11 @@ fun main() { "FormItem(${part.name},${part.value})" } is PartData.FileItem -> { - val bytes = part.streamProvider().readBytes() + val bytes = part.provider().toInputStream().readAllBytes() "FileItem(${part.name},${part.originalFileName},${hex(bytes)})" } is PartData.BinaryItem -> { - "BinaryItem(${part.name},${hex(part.provider().readBytes())})" + "BinaryItem(${part.name},${hex(part.provider().readByteArray())})" } else -> "Unknown" } @@ -59,7 +59,8 @@ fun main() { } class MultiPartContent(val parts: List) : OutgoingContent.WriteChannelContent() { - val uuid = UUID.randomUUID() + val uuid: UUID? + get() = UUID.randomUUID() val boundary = "***ktor-$uuid-ktor-${System.currentTimeMillis()}***" data class Part(