Hello everyone do you know how to upload a file su...
# ktor
d
Hello everyone do you know how to upload a file such as a pdf to an APi in compose multiplatform thanks in advance
m
Wouldn't it be a regular http POST call something like below
Copy code
val client = HttpClient()
val file = File("path/to/file.txt") // Replace with your file path

try {
    val response: HttpResponse = client.post("<https://your-server.com/upload>") {
        setBody(MultiPartFormDataContent(formData {
            append("file", file.readBytes(), Headers.build {
                append(HttpHeaders.ContentType, ContentType.Application.OctetStream)
                append(HttpHeaders.ContentDisposition, "filename=${file.name}")
            })
            // Add other form fields as needed
        }))
    }
d
Thanks so much Manas for the response is File not specific to android
a
You need to figure out how to read the file's content as
ByteArray
on each platform you support.
👍 1