Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda