This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-17
Channels
- # architecture (115)
- # asami (64)
- # aws (2)
- # babashka (65)
- # beginners (91)
- # calva (21)
- # clara (3)
- # cljdoc (5)
- # cljsrn (1)
- # clojure (331)
- # clojure-australia (15)
- # clojure-europe (16)
- # clojure-italy (7)
- # clojure-nl (8)
- # clojure-uk (10)
- # clojurescript (10)
- # conjure (4)
- # core-typed (6)
- # cryogen (12)
- # data-science (1)
- # datomic (9)
- # depstar (2)
- # emacs (1)
- # events (1)
- # figwheel-main (1)
- # fulcro (2)
- # graalvm (9)
- # helix (4)
- # java (45)
- # kaocha (4)
- # malli (14)
- # meander (4)
- # membrane (34)
- # mid-cities-meetup (6)
- # pedestal (3)
- # re-frame (7)
- # reitit (4)
- # shadow-cljs (4)
- # spacemacs (5)
- # sql (29)
- # tools-deps (22)
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?
Hi @U7RJTCH6J 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 @U0187JC6398 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?