Cleanup & save images with file extension
This commit is contained in:
parent
6583f5cb8e
commit
b3813e51de
1 changed files with 5 additions and 4 deletions
|
|
@ -5,16 +5,17 @@
|
|||
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
|
||||
[ring.middleware.logger :as logger]
|
||||
[heyarne.all-my-friends.env :refer [env]])
|
||||
(:import [java.text SimpleDateFormat])
|
||||
(:gen-class))
|
||||
|
||||
(def rfc3339 (java.text.SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ssXXX"))
|
||||
(def rfc3339 (SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ssXXX"))
|
||||
|
||||
(defn upload! [file predictions]
|
||||
(let [now (.format rfc3339 (java.util.Date.))
|
||||
uuid (java.util.UUID/randomUUID)
|
||||
ext (re-find #"\.[\w]+$" (-> file :filename))
|
||||
img-ext (re-find #"[\w]+$" (-> file :content-type))
|
||||
filename (str "uploads/" now "--" uuid)]
|
||||
(io/copy (-> file :tempfile) (io/file (str filename ext)))
|
||||
(io/copy (-> file :tempfile) (io/file (str filename "." img-ext)))
|
||||
(spit (str filename ".json") predictions)))
|
||||
|
||||
(def app
|
||||
|
|
@ -26,7 +27,7 @@
|
|||
(let [{:keys [snapshot predictions]} (-> req :params)]
|
||||
(upload! snapshot predictions)
|
||||
{:status 201
|
||||
:body (str "Thanks :)")}))}]
|
||||
:body "Thanks :)"}))}]
|
||||
["/*" (ring/create-resource-handler)]]
|
||||
{:conflicts (constantly nil)})))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue