When uploading an base64 encoded image with ktor-c...
# ktor
g
When uploading an base64 encoded image with ktor-core (common sourceset) when the image is bigger than around 200k I get the following error:
Copy code
IllegalArgumentException {message_8yp7un$_0: "should should be greater than write space + end ga… = 9, writeRemaining = 0, endGap = 8, rem+gap = 8", cause_th0jdv$_0: null, name: "IllegalArgumentException", stack: "IllegalArgumentException: should should be greater…8td$_0 (<http://localhost:9000/bundle.js:31435:19>)"}
👀 1
My base64 file represented by a string is bigger than 1MB, I guess that’s the big deal here?
I should probably upload the bytes of that file, not its representation from FileReader() in js
r
I think the best way to upload images would be using the
form-part
body request type. With that you no longer have to process the file and have no limit on its dimension
g
So you wouldn't use multi part?
r
I would use it! I send all my files using
Content-Type: multipart/form-data
and had no problem about their sizes
g
Do you have an example of form using this with ktor-client?
r
There's an example inside the official documentation: https://ktor.io/clients/http-client/calls/requests.html#multipart-form-data https://ktor.io/clients/http-client/calls/requests.html#submit-form
Copy code
val data: List<PartData> = formData {
    // Can append: String, Number, ByteArray and Input.
    append("hello", "world")
    append("number", 10)
    append("ba", byteArrayOf(1, 2, 3, 4))
    append("input", inputStream.asInput())
    // Allow to set headers to the part:
    append("hello", "world", headersOf("X-My-Header" to "MyValue"))
}
g
Ah nice I totally missed that
I only miss now how to go from the inputFile type to an inputStream or even a byteArray, who cares if we sent it in multi part correctly!
I continue to hit a buffer limit in IoBuffer in kotlin-io I guess
r
Could you post your code here?
g
@Riccardo Montagnin I posted a but to ktor.io and it seems they have already a fix for it planned for 1.1.3 https://github.com/ktorio/ktor/issues/956