Skip to content
Khaled Basbous edited this page Oct 29, 2019 · 1 revision

Welcome to the ui wiki!

How to read a file in browser

[:input {:type "file" :id "file" :name "file" :on-change put-upload}]
(defn put-upload [e]
  (let [target (.-currentTarget e)
        file   (-> target .-files (aget 0))
        reader (js/FileReader.)]
    (js/console.log target)
    (js/console.log file)
    (set! (.-onload reader) #(js/console.log (-> % .-target .-result)))
    (.readAsText reader file)))
Clone this wiki locally