I have a problem in my multiplatform project on iO...
# ktor
a
I have a problem in my multiplatform project on iOS with InvalidMutabilityException while uploading a file via KTOR. I found an issue which is marked as fixed in 1.6.2, but in my case it doesn’t help. I tried to reproduce my problem based on
client_mpp
example and found that for ByteArray with size 100 problem is not happened, but for size 200 I got an exception. here is the code of modified
ApplicationApi
Copy code
@SharedImmutable
internal expect val ApplicationDispatcher: CoroutineDispatcher

class ApplicationApi {

    // 100 - ok, 200 - kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen <object>
    private val SIZE = 200;

    private val client = HttpClient()

    private val address = Url("<https://cors-test.appspot.com/test>")

    fun about(callback: (String) -> Unit) {
        GlobalScope.launch(ApplicationDispatcher) {
            val result: String = <http://client.post|client.post> {
                url(address.toString())
                val filename = "test"
                val mimeType = "image/png"
                val filePart = formData {
                    val key = "photo"
                    val headers = Headers.build {
                        append(HttpHeaders.ContentDisposition, "filename=$filename;type=$mimeType")
                    }
                    append(key, ByteArray(SIZE), headers)
                }
                body = MultiPartFormDataContent(filePart)
            }

            callback(result)
        }
    }
}
a
This is a known issue KTOR-2947 that is, unfortunately, not fixed yet.
a
Thank for the direction.
@Aleksei Tirman [JB] Hi, Do you have any estimations when it will be fixed?
a
It will be fixed in Ktor 2.0.0 at the end of October.
a
Ohhhhh, Any suggestion for workaround?
a
@e5l do you have any?