Fork me on GitHub
#clojurescript
<
2019-02-24
>
PB04:02:32

Hey all. I have an endpoint that downloads a file. I'm trying to trigger that download from CLJS(reagent). I can see the request and the responese(inside the network tab) that shwos the file has been downloaded. but I would like to actually trigger a download that requests saving to disk. I'm unsure of where to find resources for this

henrik04:02:18

Usually for these things, it's worth checking out how it's handled in JS and then do the same thing with interop. I've never done this either, but it seems that as of HTML5, you can set a download attribute on an a element, like this: https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server

henrik04:02:11

I.e., you set the URI to be the file content. The download attribute instructs the browser to save the URI as a file rather than navigating to it.

rgm12:02:11

My recollection is that this is controlled by the content-disposition header https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

PB03:02:51

Thank you guys

PB03:02:59

I'll try this otu and report back

👍 5
daniel.spaniel15:02:21

I asked this on clojure channel but maybe this more appropriate place

daniel.spaniel15:02:23

daniel.spaniel [10:32 AM] Howdy, I am trying to send a pdf ( as ByteArrayOutputStream ) back to front end in the body of the http response. In our middle wear stack >> Transit << is barfing on that ( NullPointer ) so I am wondering if there is something I am missing. Do i have to make custom handler for transit or something? my response looks like this {:status 200 :body pdf-output-stream :headers {"Content-Type" content-type}} where pdf-output-stream is the byte array output stream

roman01la16:02:00

Hm, shouldn't your transit middleware skip byte stream payload based on content type?

daniel.spaniel16:02:40

errr ..um .. aaa .. i guess not ? i am checking the transit code and it looks like they convert output stream to byte array then to string like (String. (.toByteArray out)

daniel.spaniel16:02:49

but i just guessing

daniel.spaniel18:02:50

the answer was to create ByteArrayInputStream from the (.toByteArray out) and use that in the body

Philipp Grigoryev16:02:48

hi guys, a newb here trying to follow modern-cljs tutorial. Ran into an issue with boot-cljs-test class clojure.lang.Var$Unbound cannot be cast to class clojure.lang.IAtom Can anybody give an advice where to dig? I've already submitted an issue on the boot-cljs-test repo. Thx in advance

nanomonkey20:02:56

I'm feeling a little overwhelmed here. I'm trying to use a nodejs npm library with clojurescript. What is the preferred method to do so these days, which provides a figwheel and repl style development? Is there a tuturial or lein template that I can start off with? Thanks!

gklijs20:02:53

#shadow-cljs seems what your looking for. Is send to work better then either using npm-deps or using clojurescript with webpack.

nanomonkey20:02:30

I'll check it out. How does it differ from Lumo?

gklijs21:02:57

Don't know Lumo much. Is't an alternative clojurescript compiler, with baked in code reloading and better support for npm.

👍 5