I'm having trouble sending an http request which has a File as one of the parameters in the body. The response returned by the API is not what I'm expecting so I figure something is wrong with the code.
suspend fun post(url: String, bodyParameters: MutableMap<String, Any>, headerParameters:
MutableMap<String, String>? = null): HttpResponse?{
val client = HttpClient()
try {
val call = client.call(url) {
method = HttpMethod.Post
body = MultiPartFormDataContent(
formData {
bodyParameters.forEach{(key, value) ->
when(value) {
is String -> {
append(key, value)
}
is File -> {
append(key, value.inputStream().asInput())
}
}
}
}
)
}
if(call.response.status.value == 500) {
return null
}
return call.response
The response status that is being returned is what is expected when no File is being sent. Any ideas on why this doesn't work? Are there any other ways to do this with Ktor?