{"action":"created","issue":{"url":"https://api.github.com/repos/http-kit/http-kit/issues/269","repository_url":"https://api.github.com/repos/http-kit/http-kit","labels_url":"https://api.github.com/repos/http-kit/http-kit/issues/269/labels{/name}","comments_url":"https://api.github.com/repos/http-kit/http-kit/issues/269/comments","events_url":"https://api.github.com/repos/http-kit/http-kit/issues/269/events","html_url":"https://github.com/http-kit/http-kit/issues/269","id":138371925,"number":269,"title":"file upload from clojurescript without manually parsing org.httpkit.BytesInputStream","user":{"login":"sonwh98","id":165692,"avatar_url":"https://avatars.githubusercontent.com/u/165692?v=3","gravatar_id":"","url":"https://api.github.com/users/sonwh98","html_url":"https://github.com/sonwh98","followers_url":"https://api.github.com/users/sonwh98/followers","following_url":"https://api.github.com/users/sonwh98/following{/other_user}","gists_url":"https://api.github.com/users/sonwh98/gists{/gist_id}","starred_url":"https://api.github.com/users/sonwh98/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonwh98/subscriptions","organizations_url":"https://api.github.com/users/sonwh98/orgs","repos_url":"https://api.github.com/users/sonwh98/repos","events_url":"https://api.github.com/users/sonwh98/events{/privacy}","received_events_url":"https://api.github.com/users/sonwh98/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/http-kit/http-kit/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-04T04:04:53Z","updated_at":"2016-04-06T05:52:02Z","closed_at":"2016-04-06T05:49:39Z","body":"I am trying to upload files from ClojureScript using XMLHttpRequest  without using a form.  The ClojureScript side is working as expected but on the httpkit side the body of the request contains a org.httpkit.BytesInputStream. The content of the org.httpkit.BytesInputStream contains the uploaded files.\r\nIs there a function that will parse the stream and give me back java.io.File(s) ?\r\n\r\nThere should have been tempfile, :size and :filename in the request map http://www.luminusweb.net/docs/routes.md#handling_file_uploads  that gives me access to the File\r\nbut my request does not have those keys.  Here is my request\r\n\r\n```\r\n{:cookies {}, :remote-addr 127.0.0.1, :params {}, :flash nil, :route-params {},\r\n :headers {origin http://localhost:8080, host localhost:8080,\r\n           user-agent  \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36\"\r\n           content-type \"multipart/form-data; boundary=foo\"\r\n           content-length 6780\r\n           referer \"http://localhost:8080/85.html\"\r\n           connection \"keep-alive\"\r\n           accept \"*/*\"\r\n           accept-language \"en-US,en;q=0.8,vi;q=0.6\"\r\n           accept-encoding gzip, deflate}\r\n :async-channel #object[org.httpkit.server.AsyncChannel 0x67604a36 /127.0.0.1:8080<->/127.0.0.1:55868],\r\n :server-port 8080, :content-length 6780,\r\n :form-params {},\r\n :compojure/route [:post /upload],\r\n :websocket? false,\r\n :session/key nil, :query-params {},\r\n :content-type \"multipart/form-data; boundary=foo\"\r\n :character-encoding \"utf8\"\r\n :uri \"/upload\"\r\n :server-name \"localhost\"\r\n :query-string nil\r\n :body #object[org.httpkit.BytesInputStream 0x2262d8be BytesInputStream[len=6780]],\r\n :multipart-params {},\r\n :scheme :http\r\n :request-method :post\r\n :session {}}\r\n```\r\n\r\nand if anyone is curious here is the reagent clojurescript snippet to do fileupload without a form\r\n\r\n```\r\n [:input {:name      \"file\" :type \"file\" :multiple \"multiple\"\r\n            :on-change (fn [evt]\r\n                         (let [files (-> evt .-target .-files util/to-array)\r\n                               http-request (js/XMLHttpRequest.)\r\n                               formData (js/FormData.)]\r\n\r\n                           (doseq [[index file] (util/with-index files)]\r\n                             (println index file)\r\n                             (.. formData (append (str \"file\" index) file)))\r\n\r\n                           (aset http-request \"onreadystatechange\" (fn [evt]\r\n                                                                     (if (= 4 (. http-request -readyState))\r\n                                                                       (js/console.log (. http-request -statusText)))\r\n                                                                     ))\r\n                           (. http-request open \"post\" \"/upload\" true)\r\n                           (. http-request setRequestHeader \"Content-Type\" \"multipart/form-data; boundary=foo\")\r\n                           (. http-request send formData)))}]\r\n```\r\nthe util namespace is refers to https://github.com/sonwh98/tily/blob/master/src/com/kaicode/tily.cljc\r\n\r\nOn the serverside:\r\n\r\n```\r\n(defn upload [request]\r\n  (println \"request\" request)\r\n\r\n  (let [content (.bytes (:body request))]\r\n    (with-open [out (io/output-stream (io/file\"/home/sto/tmp/bar.txt\"))]\r\n      (.write out content)\r\n      ))\r\n  {:status 200})\r\n\r\n(defroutes all-routes\r\n           (route/resources \"/\")\r\n           (POST \"/upload\" request (upload request))\r\n           )\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/http-kit/http-kit/issues/comments/206129481","html_url":"https://github.com/http-kit/http-kit/issues/269#issuecomment-206129481","issue_url":"https://api.github.com/repos/http-kit/http-kit/issues/269","id":206129481,"user":{"login":"ptaoussanis","id":160011,"avatar_url":"https://avatars.githubusercontent.com/u/160011?v=3","gravatar_id":"","url":"https://api.github.com/users/ptaoussanis","html_url":"https://github.com/ptaoussanis","followers_url":"https://api.github.com/users/ptaoussanis/followers","following_url":"https://api.github.com/users/ptaoussanis/following{/other_user}","gists_url":"https://api.github.com/users/ptaoussanis/gists{/gist_id}","starred_url":"https://api.github.com/users/ptaoussanis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptaoussanis/subscriptions","organizations_url":"https://api.github.com/users/ptaoussanis/orgs","repos_url":"https://api.github.com/users/ptaoussanis/repos","events_url":"https://api.github.com/users/ptaoussanis/events{/privacy}","received_events_url":"https://api.github.com/users/ptaoussanis/received_events","type":"User","site_admin":false},"created_at":"2016-04-06T05:52:02Z","updated_at":"2016-04-06T05:52:02Z","body":"No problem, happy that was useful :-)"}}