[ClojureScript] File uploads in ClojureScript + React
I am currently looking at the options for supporting file uploads in several browsers in a ClojureScript SPA. My first attempt was posting a form with a file upload with cljs-http. This didn't work because the Ring/compojure app started to complain about the content boundary not being in order. Also just using cljs-http will not work for IE9 of course. Next, I gave goog.net.iframeIO a try. This will work for the spectrum of browsers we have to support, but working with iframes for modern browsers doesn't feel right. Then I tried jquery-file-upload. Still playing around with it, but I'm pretty sure this will give me what I need, as it has a fallback mechanism for older browser via iframe transport. I wonder what other options I have and what is convenient in combination with React and ClojureScript. Feel free to post some examples to your open source projects or give any other helpful tips. Thanks, Michiel Borkent -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups ClojureScript group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.
[ClojureScript] Re: Saving a file
On Friday, February 13, 2015 at 6:05:37 PM UTC+11, Jensontech wrote: I need to allow the user to save content generated by Clojurescript to their local drive. I do it using this code - (defn- save-file [filename content] (let [lnk (get-element-by-id file-export-link) blob (js/Blob. (js/Array. content) {:type text/plain})] (set! (.-href lnk) (.createObjectURL js/URL blob)) (set! (.-download lnk) filename) (.click lnk))) When the function runs it does a pseudo download to the named file. This works with :optimizations :none. When I try the same thing with :optimizations :advanced, instead of doing a download and prompting to open or save a file, it moves the browser to a URL like: blob:null/d9bbcdab-7c87-etc I have tried Chas Emericks's url package https://github.com/cemerick/url to create the URL but it still doesn't work. Something is being munged by the optimization, but I am not sure what. Does anyone have any ideas how to go about fixing this? I hesitate to offer advice here, because I'm just finding my way in these sort of matters myself but ... 1. You are using HTML5 APIs: Blob and URL. 2. Your code works with optimisation :none, but not :advanced 3. I conclude that advanced optimisation is munging the symbols. 4. Which means you need to include externs for this API for URL and Blob) This appears to be the right set of externs: https://code.google.com/p/closure-compiler/source/browse/externs/fileapi.js But at that point, I run out of knowing much. Because it is part of Google Closure, you'd think there was some way of pulling in that file. Background: http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html Alternative thought ... Perhaps you could the `goog` wrappers for the HTML5 API: http://docs.closure-library.googlecode.com/git/namespace_goog_fs.html (But I can't see how to get a Blob). (ns my.module (:require [goog.fs :as fs])) ;; later (.createObjectUrl fs blob) ;; or maybe (fs/createObjectUrl blob) ;; BUT no idea how to create a Blob in the first place. -- Mike -- Mike -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups ClojureScript group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.
[ClojureScript] Re: File uploads in ClojureScript + React
On Saturday, February 14, 2015 at 3:26:53 PM UTC+1, Michiel Borkent wrote: I am currently looking at the options for supporting file uploads in several browsers in a ClojureScript SPA. My first attempt was posting a form with a file upload with cljs-http. This didn't work because the Ring/compojure app started to complain about the content boundary not being in order. Also just using cljs-http will not work for IE9 of course. Next, I gave goog.net.iframeIO a try. This will work for the spectrum of browsers we have to support, but working with iframes for modern browsers doesn't feel right. Then I tried jquery-file-upload. Still playing around with it, but I'm pretty sure this will give me what I need, as it has a fallback mechanism for older browser via iframe transport. I wonder what other options I have and what is convenient in combination with React and ClojureScript. Feel free to post some examples to your open source projects or give any other helpful tips. Thanks, Michiel Borkent Why do you need a plugin at all ? A basic form with the input type=file should work fine. form method=post enctype=multipart/form-data input type=file name=[some name] / input type=submit value=Upload / /form Supported since IE 3.0 I think... -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups ClojureScript group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.