Fork me on GitHub
#re-frame
<
2018-11-30
>
oliy10:11:08

i made a thing, not sure if it goes against some explicit decision in re-frame or not. it allows you to tee an event handler so that you can pipe it to multiple handlers https://github.com/oliyh/alrightee

manuel11:11:48

hi everybody. A problem with file uploading: - I have a form (in my views.cljs) with an input of type "file" - I have an upload button that should dispatch the file uploading event to the server via ajax I have an event on the on-change of the input "file" that fires this:

(rf/reg-event-db
 ::new-version-store-multipart
 (fn [db [_ _]]
   (let [input-element (.getElementById js/document "file")
         name (.-name input-element)
         files (.-files input-element)
         form-data (let [f-d (js/FormData. "file-form")]
                     (doseq [file-key (.keys js/Object files)]
                       (.append f-d name (aget files file-key)))
                     f-d)]
     (assoc-in db [:document-details :new-version :multipart] form-data))))
But form-data is always empty.

manuel11:11:15

And the event the do the actual ajax calls sends nil to the server.

manuel13:11:47

my bad, at further inspection form-data has a value in it. Just need not properly send it to the server now. 🙂