Fork me on GitHub
#clj-http
<
2024-03-07
d._.b17:03:37

I'm converting from hato to clj-http (don't ask), and multipart is not working for me no matter what I do

d._.b17:03:42

In hato, it's just :multipart [{:name "request_body" :content-type "form-data" :content (json/encode body)}] in clj-http im trying: :multipart [{:name "request_body" :content (json/encode body) :encoding "UTF-8" :mime-type "form-data"}]

mmer17:03:56

This works for me:

(http/post url
                  {:client client
                   :headers {"Accept" "application/json"
                             ...}
                   :multipart [{:name "file" :content content
                                :file-name filename}]})

d._.b17:03:14

maybe i don't understand multipart -- what is the filename here?

mmer17:03:52

I just set it to the filename of the file I am sending in the content. It is just the filename not the path.

mmer17:03:08

What is the error you are getting?

d._.b17:03:16

that the server has an error reteiving a part of the multipart message

d._.b17:03:42

so not very specific

d._.b17:03:55

but hato Just Works, and im struggling to get clj-http to work

mmer17:03:32

I may have answered incorrectly as I was using clj-http - and moved to use babashka.http-client as I am using bb. Sorry, I may not be the best to answer this.

d._.b18:03:24

no problem, thanks

d._.b20:03:04

It looks like hato includes: content-type: multipart/form-data; boundary=hatoBoundarynSKqshIB6Wf6VnFhxnWPdnY6rkS2nH in the headers whereas clj-http does not

d._.b20:03:22

i guess that brings up the question: how do i set the boundary if im manually handling content type?