Created
June 18, 2020 15:21
-
-
Save zoren/cc74758198b503b1755b75d1a6b376e7 to your computer and use it in GitHub Desktop.
Download a BLOB via a object URL in ClojureScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; heavily inspired by Mariano Guerra | |
;; http://marianoguerra.org/posts/download-frontend-generated-data-to-a-file-with-clojurescript.html | |
(defn download-blob [file-name blob] | |
(let [object-url (js/URL.createObjectURL blob) | |
anchor-element | |
(doto (js/document.createElement "a") | |
(-> .-href (set! object-url)) | |
(-> .-download (set! file-name)))] | |
(.appendChild (.-body js/document) anchor-element) | |
(.click anchor-element) | |
(.removeChild (.-body js/document) anchor-element) | |
(js/URL.revokeObjectURL object-url))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment