Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda