Hey! :wave: Using `MultiPartFormDataContent` to se...
# ktor
n
Hey! 👋 Using
MultiPartFormDataContent
to set the boy of a request in the like:
Copy code
setBody(
                MultiPartFormDataContent(
                    formData {
                        append("pub_id", pubId)
                        append("logo", logo, Headers.build {
                            append(HttpHeaders.ContentType, contentType)
                            append(HttpHeaders.ContentDisposition, "filename=\"$logoName\"")
                        })
                    }
                )
            )
on the server side (not Ktor) I’m getting the following:
Copy code
{
  fields: {
    "nt-Disposition: form-data; name=pub_id\r\nContent-Length: ": "30"
  },
  files: {
    "nt-Disposition: form-data; name=log": {
      name: "nt-Disposition: form-data; name=log",
      filename: "Foto May 14 2024.jpg",
      contentType: "image/jpeg\r\nContent-Length: 6371508",
      size: 6371508,
      content: Uint8Array(6371508) [...]
    }
  }
}
As you can see, the Content-Disposition header is interpreted as part of the parameters and everything gets messy. The server side is working as expected when sending the request with Postman, though. Any idea what could be happening? Thanks!
According to Postman, the correct way to send this parameter with OkHTTP would be:
Copy code
addFormDataPart("logo","Foto May 14 2024.jpg",
    RequestBody.create(MediaType.parse("application/octet-stream"),
    new File("/Users/ignacio.ruizmartin/Downloads/Foto May 14 2024.jpg")))
I’m surprised about the
application/octet-stream
part, shouldn’t that be the Mime Type of the file?
By the way, the raw Form Data in KJS looks OK, but the parsed one is empty.
a
The raw form data looks well-formed to me. Can you try receiving the content using another server framework?
n
Sure, I’ll try 🙂
Yes, it works with a different server framework…
That is weird, because it worked in Postman but, anyway, it ended great.
Thanks!