我从 KMP 项目中的相机获取 ByteArray 并尝试将其上传到服务器。
我试试这个
val response = client.post(url) {
setBody(
MultiPartFormDataContent(
formData {
if (byteArrays != null) {
append("image", byteArrays, Headers.build {
append(HttpHeaders.ContentType, "image/png")
append(HttpHeaders.ContentDisposition, "filename=${name}")
})
}
},
)
)
onUpload { bytesSentTotal, contentLength ->
println("Sent $bytesSentTotal bytes from $contentLength")
}
}
但是错误
"Required request part 'file' is not present"
看起来您已指定“image”作为表单数据的键名称。也许尝试将其切换为“文件”。