Thread
#multiplatform
    Elnur Jeksenov

    Elnur Jeksenov

    1 year ago
    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 java.io.file in kotlin multiplatform. Have you got any idea to solve this problem?
    a

    Andrew

    1 year ago
    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 java.util.date 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

    Elnur Jeksenov

    1 year ago
    I didn’t get your question. I have tried to use this library, there is no files support. It’s unavailable yet.
    Animesh Sahu

    Animesh Sahu

    1 year ago
    In common create
    expect class File { /* Bunch of utility ... */ fun abc(): ReturnType }
    It behave similar to interface In JVM do
    actual typealias File = <http://java.io|java.io>.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

    Elnur Jeksenov

    1 year ago
    <http://httpClient.post|httpClient.post>(url) {
                body = MultiPartFormDataContent(
                    formData {
                        this.appendInput(
                            key = "first_file_uploaded",
                            headers = Headers.build {
                                append(HttpHeaders.ContentDisposition,
                                    "filename=$fileName")
                            }
                        ) {
                            buildPacket { writeFully(byteArray) }
                        }
                    }
                )
            }
    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?