Skip to content

Instantly share code, notes, and snippets.

@irneh
Created April 5, 2014 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irneh/9986405 to your computer and use it in GitHub Desktop.
Save irneh/9986405 to your computer and use it in GitHub Desktop.
(defn move-to-s3 [k f]
(s3/put-object :bucket-name s3-bucket
:key k
:file f)
(io/delete-file f))
(defn upload [userid file]
(let [img-uuid (uuid)
exts [".orig.jpg" ".0.jpg" ".1.jpg"]
dims [[nil nil] [595 296] [180 120]]
names (map #(str img-uuid %) exts)
paths (map #(str tmp-dir %) names)
name-orig (nth names 0)
path-orig (nth paths 0)
variants (map cons paths (map cons names dims))
;; Rename the incoming file before writing it.
file (assoc-in file [:filename] name-orig)]
(noir/upload-file tmp-dir file)
(let [exif (file->exif path-orig)
taken (get-exif-date exif)]
(doseq [[path filename width height] variants]
(when width
(resize-img path-orig path width height)))
(doseq [[path file _ _] variants]
(move-to-s3 file path))
(write-photo-db img-uuid userid taken)
(html exif))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment