fuel icon indicating copy to clipboard operation
fuel copied to clipboard

[Ask] multipart/form-data with header use

Open rraayy opened this issue 5 years ago • 0 comments

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. 螢幕快照 2019-07-06 16 21 14

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?

rraayy avatar Jul 06 '19 14:07 rraayy