Fork me on GitHub
#beginners
<
2021-09-19
>
zendevil.eth07:09:41

I’m trying to send a file and other data to the server using http-xhrio (re-frame wrapper around cljs-ajax) like so:

{:http-xhrio {:method          :post
                :uri             (str (endpoint) "/create-ipfs")
                :timeout         40000
                :format (ajax/json-request-format {:keywords? true})
                :response-format (ajax/json-response-format {:keywords? true})
                :multipart-params [["token-image" (:token-image db)]
                                   ["token-name" (:token-name db)]
                                   ["description" (:description db)]]           
                :on-success      [:created-ipfs]
                :on-failure      [:error-occured]}}
but on the server side, the multipart-params map is empty. How to fix that?

delaguardo10:09:45

https://github.com/JulianBirch/cljs-ajax#getpostput instead of multipart-params you should use :body with js/FormData instead

az20:09:59

Hi all, wondering if anyone can explain what :meta portion of this does exactly? I have a situation when I remove that portion I get errors in clojurescript.

(atom {} :meta {:listeners (atom {})})

Fredrik20:09:42

The :meta sets the metadata on the atom to whatever comes after :meta , if that's what you're asking.

Fredrik20:09:06

What error are you getting?

az21:09:45

@U024X3V2YN4 sorry for not including. This is really a datascript thing. When I listen! I get the error if not included:

(defn listen!
  "Listen for changes on the given connection. Whenever a transaction is applied to the database via [[transact!]], the callback is called
   with the transaction report. `key` is any opaque unique value.
   
   Idempotent. Calling [[listen!]] with the same key twice will override old callback with the new value.
   
   Returns the key under which this listener is registered. See also [[unlisten!]]."
  ([conn callback] (listen! conn (rand) callback))
  ([conn key callback]
     {:pre [(conn? conn) (atom? (:listeners (meta conn)))]}
     (swap! (:listeners (meta conn)) assoc key callback)
     key))

Fredrik22:09:04

(swap! (:listeners (meta conn)) assoc key callback)
here it is expecting that the metadata on the connection points to an atom. Thus there is a preconditien check in :pre that checks specifically for this.

Fredrik22:09:15

I'm guessing you are getting Assert failed errors?

az23:09:50

@U024X3V2YN4 Yes exactly. Thank you for the explanation. I thought maybe there was an idiom here outside of datascript.

Fredrik00:09:17

The usage of metadata differ wildly from library to library. Many don't use it at all, while those that do, often use it in a library-internal way and hence having the correct metadata can become essential. Here you have a clear example of the latter.