Rok Oblak
07/11/2024, 10:53 AMsetBody(MultiPartFormDataContent(formData {
...
append("file", bytes, Headers.build {
append(HttpHeaders.ContentType, ContentType.Application.OctetStream.toString())
})
}))
but when observing the progress (via the onUpload
listener), it seems that all the bytes are immediately uploaded to my ktor server.
The server is localhost, but it makes an S3 upload via the S3 putObject
which receives an InputStream
, and this input stream is just part.streamProvider()
.
So I am guessing the issue is not the server (it should not read all bytes first and then upload to S3) but my client, probably append("file", bytes,
does not upload in a streamed fashion (please correct me if I am wrong).
So my question is: what method can I use in a multplatform ktor client which appends a stream multipart?Aleksei Tirman [JB]
07/11/2024, 2:35 PMfile
part?Rok Oblak
07/11/2024, 2:36 PMAleksei Tirman [JB]
07/11/2024, 2:43 PMonUpload
handler in the following code is called for every 4088 bytes written:
val client = HttpClient(OkHttp)
val request = HttpRequestBuilder().apply {
url("<https://httpbin.org/post>")
method = HttpMethod.Post
setBody(
MultiPartFormDataContent(
formData {
append("file", File("path/to/file").readBytes())
}
)
)
onUpload { written, total ->
println(written)
}
}
val response = client.request(request)
Rok Oblak
07/11/2024, 2:48 PMinputStream = part.streamProvider()
PutObjectRequest(config.bucketName, key, inputStream, metadata)
The only suspect I see is the suspending forEachPart
function, which I am not sure if it suspends until it receives all parts, even though when receiving FileItem
I do not do anything with it. Will debug more.