Todd
08/08/2024, 4:41 PMsteamProvider()
and use the inputStream to consume the file. However, I modifed this code to use provider()
since streamProvider()
is deprecated. First, I'm not sure how I can just consume this as kotlinx.io.Source without reading the whole thing into memory. Regardless, I tried provider().readRemaining()
but I got the error in the thread 🧵Todd
08/08/2024, 4:41 PMjava.io.EOFException: Not enough data available, required 106496 bytes but only 0 available
at io.ktor.utils.io.ByteReadChannelOperationsKt.readPacket(ByteReadChannelOperations.kt:320)
at io.ktor.http.cio.MultipartKt$parseMultipart$1.invokeSuspend(Multipart.kt:267)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:231)
at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:187)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:159)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:466)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:500)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:489)
at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:364)
at io.ktor.utils.io.ByteChannel.resumeSlot(ByteChannel.kt:166)
at io.ktor.utils.io.ByteChannel.moveFlushToReadBuffer(ByteChannel.kt:79)
at io.ktor.utils.io.ByteChannel.awaitContent(ByteChannel.kt:68)
at io.ktor.utils.io.ByteChannel$awaitContent$1.invokeSuspend(ByteChannel.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
Todd
08/08/2024, 4:42 PMAleksei Tirman [JB]
08/09/2024, 7:35 AMTodd
08/09/2024, 3:38 PMTodd
08/22/2024, 12:54 AMAleksei Tirman [JB]
08/22/2024, 9:07 AM@Test
fun test() = testApplication {
routing {
post {
call.receiveMultipart().forEachPart { part ->
when (part) {
is PartData.FileItem -> {
val bytes = part.provider().readRemaining().readByteArray()
assertEquals(1 * 1024 * 1024, bytes.size)
}
else -> {}
}
}
}
}
client.post {
setBody(MultiPartFormDataContent(formData {
append("file", ByteArray(1 * 1024 * 1024) { 1 }, Headers.build {
append(HttpHeaders.ContentType, "image/png")
append(HttpHeaders.ContentDisposition, "filename=\"ktor_logo.png\"")
})
}))
}
}
However, I cannot reproduce this problem with Ktor built from the main branch, so the upcoming RC version must contain the fix.Todd
08/22/2024, 1:28 PM