如果我使用submitFormWithBinaryData(),如何向 ktor 请求添加标头?
下面的代码是使用 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}")
})
}
)
Code below is to upload an file using ktor and 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}")
})
}
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法使用
submitFormWithBinaryData
方法来执行此操作。使用 post 或 请求方法。这是一个例子:You can't do that using the
submitFormWithBinaryData
method. Use the post or request method. Here is an example:这是我的代码...
this is my code ...