0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 17:21:17 -05:00

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]
rs/WatchEvent
(-apply-watch [_ state s]
(let [image-data {:coll coll-id
:id (uuid/random)
:files files}]
(->> (rp/req :create/image image-data)
(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)
:file file}) (files-to-array files))]
(->> (rx/from-coll images-data)
(rx/flat-map #(rp/req :create/image %))
(rx/map :payload)
(rx/map image-created)))))

View file

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

View file

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