# multiplatform

Elnur Jeksenov

11/18/2020, 5:17 AM
Hi guys👋 My android project contains three modules: 1. app 2. ui(jetpack compose) 3. sdk(kotlin multiplatform, ktor client) So I’m making requests to server in sdk(kotlin multiplatform) module. I want to upload file via multipart-form-data, but there is no support for in kotlin multiplatform. Have you got any idea to solve this problem?


11/18/2020, 6:13 AM
I have not used a lot of the things in this setup but have an idea of how it might work. How would you send some random bytes of data from a byte[] array?
If that works then there might be some other library to handle files in KMP or you can just write your own file class using expect/actual. I did similar for recently.
Basically each platform needs to do its implementation of file io (via library or you code it) which can abstract it so KMP can use it. ktor client is doing that for the network layer

Elnur Jeksenov

11/18/2020, 6:41 AM
I didn’t get your question. I have tried to use this library, there is no files support. It’s unavailable yet.

Animesh Sahu

11/18/2020, 8:18 AM
In common create
expect class File { /* Bunch of utility ... */ fun abc(): ReturnType }
It behave similar to interface In JVM do
actual typealias File = <|>.File
In iOS or something like that do the same In native use Posix API and create your own File class implementing
actual class File {...}

Elnur Jeksenov

11/18/2020, 11:05 AM
Copy code
<|>(url) {
            body = MultiPartFormDataContent(
                formData {
                        key = "first_file_uploaded",
                        headers = {
                    ) {
                        buildPacket { writeFully(byteArray) }
Copy code
kotlinx.serialization.SerializationException: Serializer for class 'MultiPartFormDataContent' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
there is exception. Have you got any idea to make ‘MutliPartFormDataContent’ serializable?