add stream using for multipart

This commit is contained in:
InsanusMokrassar 2021-12-14 22:03:29 +06:00
parent 1ee5b4bfd4
commit eb562d8784

View File

@ -14,9 +14,10 @@ import io.ktor.request.receiveMultipart
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.response.respondBytes import io.ktor.response.respondBytes
import io.ktor.routing.Route import io.ktor.routing.Route
import io.ktor.util.asStream
import io.ktor.util.cio.writeChannel
import io.ktor.util.pipeline.PipelineContext import io.ktor.util.pipeline.PipelineContext
import io.ktor.utils.io.core.Input import io.ktor.utils.io.core.*
import io.ktor.utils.io.core.readBytes
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.* import kotlinx.serialization.*
import java.io.File import java.io.File
@ -182,7 +183,9 @@ suspend fun <T> ApplicationCall.uniloadMultipartFile(
name.nameWithoutExtension, name.nameWithoutExtension,
".${name.extension}" ".${name.extension}"
).apply { ).apply {
writeBytes(it.provider().readBytes()) outputStream().use { fileStream ->
it.provider().asStream().copyTo(fileStream)
}
} }
} }
"data" -> data = standardKtorSerialFormat.decodeDefault(deserializer, it.provider().readBytes()).optional "data" -> data = standardKtorSerialFormat.decodeDefault(deserializer, it.provider().readBytes()).optional
@ -216,7 +219,9 @@ suspend fun ApplicationCall.uniloadMultipartFile(
name.nameWithoutExtension, name.nameWithoutExtension,
".${name.extension}" ".${name.extension}"
).apply { ).apply {
writeBytes(it.provider().readBytes()) outputStream().use { fileStream ->
it.provider().asStream().copyTo(fileStream)
}
} }
} else { } else {
onCustomFileItem(it) onCustomFileItem(it)