Created
April 5, 2014 01:44
-
-
Save irneh/9986405 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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