r0man / cljs-http

A ClojureScript HTTP library.
582 stars 93 forks source link

Binary data doesn't seem to be included with multipart post? #130

Closed EdwardIII closed 3 years ago

EdwardIII commented 3 years ago

I'm certain this is something I'm doing, not a bug.

When I try to send a file like this:

  (go
    (let [response (<! (http/post "/"
                                  {:with-credentials? false
                                  :multipart-params [["__anti-forgery-token" (upload-request :csrf-token)]
                                                     ["my-file" (upload-request :file) ]]}))])))

It seems all the metadata gets sent, but not the actual binary data?

------WebKitFormBoundaryvKFgMvNJnKVWnJMQ
Content-Disposition: form-data; name="__anti-forgery-token"

/0/9UcJilaQXp3EVVfLm5HrU16venLQ/Fbaddbng32/KzmJC5nGDX0ibmR2OuWNqJWDxaZlHK2h/HAZj
------WebKitFormBoundaryvKFgMvNJnKVWnJMQ
Content-Disposition: form-data; name="my-file"; filename="sample.png"
Content-Type: image/png

------WebKitFormBoundaryvKFgMvNJnKVWnJMQ--

Here's the function:

https://gist.github.com/EdwardIII/ad7932af3ebf057b5d8127ec10a00a5e#file-02-uploader-cljs

I'm trying to upload from a file drag & drop:

https://gist.github.com/EdwardIII/ad7932af3ebf057b5d8127ec10a00a5e#file-03-whole-file-clj

Pretty sure the values I'm passing in are good, here's the result of (println upload-request):

{:file #object[File [object File]], :csrf-token /0/9UcJilaQXp3EVVfLm5HrU16venLQ/Fbaddbng32/KzmJC5nGDX0ibmR2OuWNqJWDxaZlHK2h/HAZj}

It is a File object, but that inherits from Blob so I'm thinking it should work in the same way:

image

EdwardIII commented 3 years ago

Ah no, it looks like it was actually working, but it's just that Chrome is a bit secretive about the binary data it's sending and doesn't include it in "copy as cURL" from the network tab.