Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Post request with an image using Ktor client

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?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!