Fork me on GitHub
Andreas S.20:11:05

Hi! is it possible to load a local file with clojurescipt? Any ideas appreciated!


where are you running your clojurescript? in the browser? locally, with nodejs?


I would use javascript interop to get the file using the apis like . I would give a better answer but it’s pretty late here.

Andreas S.08:11:04

Thanks for answering! Could you sketch out how I would call this from cljs? Take your time, you don’t have so answer right away :)


Here’s a snippet that may help you (Reagent/Hiccup):

(defn get-file []
  (let [handle-change (fn [event]
                        (let [files (.. event -target -files)
                              file (first (js->clj files))]
                          (println file)))] ;; do something with file
    [:input {:type "file"
             :on-change handle-change}]))

Andreas S.20:11:14

hi @U0187JC6398 thank you for answering! lets say I have a "" in the same directory as my cljs file, where would I put file name and or path information in your function?


to do that, you would have to use a clojure macro that reads the file at compile time and makes the data available when the clojurescript code is eventually run in the browser

Andreas S.08:11:53

Could I read the data into data script or something?

Andreas S.08:11:18

I mean if I turn my markdown files into clojurescript source code files, then it should work?