O the re-frame frontend, I have a link with a on-click calling cljs-ajax GET:
:on-click #(GET "/csv" {:params param})
When I hit http://localhost:3000/csv, it works, the file gets downloaded. But when I click on the frontend button, it does not work, the response is displayed in the console but the file does not get downloaded.
I’ve explored possible solutions with :response-format within the GET sexp, but was not able to sort this. I’m pretty sure I’m missing something obvious, but like many obvious things, I’m probably too close to notice it (yeah, I’ve spent some time on this!)
If anyone is able to push me in the right direction or to provide a working minimal example, I’d be very grateful! Thanks a lot.
Here’s a function that might work for you. It creates an anchor element and simulates a click. You’ll have to get the response from your GET invocation and grab the appropriate headers.
The thing is I had to add the query parameters to the regular link, which looks hackish to me.
I’m still interested on what is the expected way of dealing with this general issue (i.e. send a cljs-ajax request to a server and download a file as a result.)
Thanks to both of you for taking the time to answer this already!
Here’s a more complete example using re-frame and re-frame-http-fx. Clicking the Download button will fetch the json response and save it to a file. Hope that helps.