Description
At the moment it doesn't seem possible to send files as multipart/form-data
as described here: Using the Fetch API - Web APIs | MDN.
For example with js/fetch
we could do something like this:
(-> (js/fetch "https://example.com/profile/avatar"
#js{:method "POST"
:body (doto (js/FormData.) (.append "file" blob file-name))})
and js/fetch
will automatically set the Content-Type
header to multipart/form-data
and encode the body properly.
However in lambdaisland/fetch the body is always encoded according to the :content-type
option before it's passed to js/fetch
(unless it's a string):
fetch/src/lambdaisland/fetch.cljs
Lines 102 to 104 in 1fe9fab
There isn't really a way to leave the body decoded without passing a string.
I think the simplest workaround would probably be to add a new :raw
or nil
option for :content-type
that just passes the :body
through to js/fetch
decoded.
It's possible to bypass the encoding today by using :default
as the :content-type
, but that will also explicitly set the Content-Type
header to nil
, since it's not in the content-types
map and is really just a hack for the encoding multimethod.
fetch/src/lambdaisland/fetch.cljs
Lines 80 to 81 in 1fe9fab