Hey all, I'm trying to upload a data class to S3 a...
# ktor
a
Hey all, I'm trying to upload a data class to S3 as JSON using a presigned URL, but I am experiencing issues with the
ContentNegotiation
plugin. It looks like the
ContentNegotiation
plugin always uses
Transfer-Encoding: chunked
which is a problem for S3. This limits me to having to manually serializes this object before uploading it. Is there any way to turn off this behavior? I've scoured the web but found no way to do this as of yet...
p
It looks like it will use chunked encoding if the content length is unknown (or the headers indicate to use chunked) (at least for CIO client)
r
We use AWS SDK for Kotlin to interact with S3. While it's not a fix for your particular issue, I suggest it as an alternative solution. It works really well with Kotlin apps
a
Yeah wish we could @Renan Kummer, but this is part of a larger system which passes us the presigned URL so we can upload to S3 and we can't change that system sad panda
@phldavies Right, we're using OkHttp as the engine and get the same behavior. AWS doesn't support that for S3. So essentially our options are: 1. Serialize the object ourselves prior to passing to Ktor (i.e. turning the object into a JSON string) 2. Develop an interceptor which removes the
Transfer-Encoding
header and updates the
Content-Length
with a manually calculated body size Neither of these options are particularly great so I was hoping that we'd be able to find an alternative here that would help us out sad panda
a
What content converter do you use? As I can see from the code, the
ContentNegotiation
plugin with
KotlinxSerializationConverter
serializes requests to the
TextContent
and
ByteArrayContent
types that have a known content length (no chunked encoding).
a
@Aleksei Tirman [JB] we're using Jackson. I was under the impression these would work similarly?
a
By default, the
JacksonConverter
streams the body by using the
OutputStreamContent
. You can disable streaming by passing
false
to the
streamRequestBody
parameter when calling the
jackson
configuration method.
a
Ahhhhh, that would make sense. I'll have to try making that change!