Hey! Can I use Ktor client to upload a file as a s...
# ktor
n
Hey! Can I use Ktor client to upload a file as a single binary file instead of using multipart? I have the need to upload a file to aws s3 and it doesn’t work as expected with a single-part multipart, but testing from Postman using “binary” works. Would there be any way to do that? Also, I can’t use
submitFormWithBinaryData
because AWS S3 expects a
PUT
and not a
POST
1
a
You can use the
setBody
method to send a binary body. Here is an example:
Copy code
val client = HttpClient(OkHttp)

val r = <http://client.post|client.post>("<https://httpbin.org/post>") {
    setBody(File("data.bin").readChannel())
}
println(r.bodyAsText())
n
Waaay easier than expected. Thanks, mate.
For future reference, I had to also set the Content-Type manually (not able to use ByteChannel here).
191 Views