Upload multiple images

This commit is contained in:
Jesús Espino 2016-05-23 20:03:12 +02:00
parent 4237f3a04e
commit 3a7e97bc60
3 changed files with 13 additions and 6 deletions

View file

@ -171,10 +171,16 @@
(defrecord CreateImages [coll-id files] (defrecord CreateImages [coll-id files]
rs/WatchEvent rs/WatchEvent
(-apply-watch [_ state s] (-apply-watch [_ state s]
(let [image-data {:coll coll-id (let [files-to-array (fn [js-col]
(-> (clj->js [])
(.-slice)
(.call js-col)
(js->clj)))
images-data (map (fn [file] {:coll coll-id
:id (uuid/random) :id (uuid/random)
:files files}] :file file}) (files-to-array files))]
(->> (rp/req :create/image image-data) (->> (rx/from-coll images-data)
(rx/flat-map #(rp/req :create/image %))
(rx/map :payload) (rx/map :payload)
(rx/map image-created))))) (rx/map image-created)))))

View file

@ -46,9 +46,9 @@
(send! params))) (send! params)))
(defmethod request :create/image (defmethod request :create/image
[_ {:keys [coll id files] :as body}] [_ {:keys [coll id file] :as body}]
(let [body (doto (js/FormData.) (let [body (doto (js/FormData.)
(.append "file" (aget files 0)) (.append "file" file)
(.append "id" id)) (.append "id" id))
params {:url (str url "/library/image-collections/" coll "/images") params {:url (str url "/library/image-collections/" coll "/images")
:method :post :method :post

View file

@ -208,6 +208,7 @@
[:span "+ New image"] [:span "+ New image"]
[:input.upload-image-input [:input.upload-image-input
{:style {:display "none"} {:style {:display "none"}
:multiple true
:ref "file-input" :ref "file-input"
:type "file" :type "file"
:on-change on-file-selected}]]) :on-change on-file-selected}]])