fuel
fuel copied to clipboard
[Ask] multipart/form-data with header use
Hi, Meets some problem when using fuel in Kotlin.
I have to upload a image and also needs with some data like "name" and "id" like the attached image in Postman.
I also need to add "Authorization" in the header.
below is my code
var paraList = listOf("name" to name)
val (request, response, result) = Fuel.post(path,paraList)
.header(mapOf("Content-Type" to "multipart/form-data",
"Authorization" to "Bearer " + MyToken)
.upload()
.add(FileDataPart(image,"image",image.name))
.responseString()
`
`
result.fold(
success = {json ->
LogUtil.d("sendCreateMember -> $json")
},
failure = {error ->
LogUtil.d("sendCreateMember error -> $error")
}
)
I have no idea why always got the HTTP Exception 400 Bad Request
anyone can help me?