http-client icon indicating copy to clipboard operation
http-client copied to clipboard

Unexpected error with multipart request

Open martinklepsch opened this issue 11 months ago • 1 comments

I'm not sure if this is expected but I was working with an API expecting a multipart upload and it tripped up whenever I would set the content type header according to the documentation. The below snippet exhibits the same behavior.

Not setting the content type header resulted in a successful request.

I don't fully understand why but thought I'd raise as feedback.

(http/post "https://postman-echo.com/post"
           {:headers {"Content-Type" "multipart/form-data"}  ; < -- this made the request fail
            :multipart [{:name "title" :content "My Title"}
                        {:name "file" :content (io/file test-file) }]})

martinklepsch avatar Dec 29 '24 21:12 martinklepsch

I'm not familiar with this API but what was the error you got back from the API?

borkdude avatar Dec 29 '24 21:12 borkdude

The reason this happens is that when using multipart, the content type should be something like "multipart/form-data; boundary=babashka_http_client_Boundary7f8662ac-e551-4a60-9be3-786d7743724a" which is what babashka.http-client adds automatically. When not specifying the boundary, the API will send back a 500 that says that the boundary is missing. To solve this issue, we could dissoc "Content-Type" or so.

borkdude avatar Jun 05 '25 19:06 borkdude