Hi! is it possible to load a local file with clojurescipt? Any ideas appreciated!
Hi @smith.adriane in the browser
I would use javascript interop to get the file using the apis like https://web.dev/read-files/ . I would give a better answer but it’s pretty late here.
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}]))
hi @tom.bowden thank you for answering! lets say I have a "README.md" 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
Could I read the data into data script or something?
I mean if I turn my markdown files into clojurescript source code files, then it should work?
where are you running your clojurescript? in the browser? locally, with nodejs?