Joey
03/25/2022, 2:12 PMJoey
03/25/2022, 2:12 PMwithContext(<http://platformDispatchers.IO|platformDispatchers.IO>) {
client.put<Unit>(urlString = uploadUrl) {
body = StreamContent(File(fileInfo))
}
}
Joey
03/25/2022, 2:12 PMprivate class StreamContent(
val file: File,
override val contentType: ContentType = ContentType.Application.OctetStream,
) : OutgoingContent.WriteChannelContent() {
override suspend fun writeTo(channel: ByteWriteChannel) {
channel.bufferedWriter().use { output ->
file.bufferedReader().use { input ->
input.copyTo(output)
}
}
}
override val contentLength: Long = file.length()
}
David Nedrow
03/25/2022, 4:15 PMfile.bufferedReader()
attempts to load the whole file in local memory? I'm not entirely sure how BufferedReader works in that regard, and the docs aren't clear.