下面的代码是使用 ktor 和 kmm 上传文件...
val client = HttpClient(Apache) {}
val file = File("path/to/some.file")
val chatId = "123"
client.submitFormWithBinaryData(
url = "https://api.telegram.org/bot<token>/sendDocument?chat_id=$chatId",
formData = formData {
append("document", file.readBytes(), Headers.build {
append(HttpHeaders.ContentDisposition, "filename=${file.name}")
})
}
)