Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:404636
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
import Hack
import qualified Web.Encodings as Web
import Data.ByteString.Lazy.Char8 as BS
 
galleryDispatch ai@(\x -> head (pElements x) -> "u") =
case requestMethod (a_env ai) of
POST -> do
dbg "galleryDispatch: POST on /upload."
let env = a_env ai
case ((,) <$> lookup "Content-Type" (http env)
<*> lookup "Content-Length" (http env)) of
Nothing -> do
dbg "Ack!"
redirect' "/profile"
Just (ty,_len) -> do
dbg $ "TY: " ++ (show ty)
let bound = replace "boundary=" "" $ head $ drop 1 $ split " " ty
dbg $ "Boundary: " ++ (show bound)
 
let uid = fromJust $ a_uid ai
-- For testing, I'm just going to send one image
let (_,[(a,fi)]) = Web.parseMultipart bound $ hackInput env
dbg $ "a: " ++ (show $ BS.unpack a)
dbg $ "Content-Type: " ++ (show $ BS.unpack $ Web.fileContentType fi)
let filename = BS.unpack $ Web.fileName fi
dbg $ "Filename: " ++ (show filename)
 
let s3o_bucket = "static.iplayedthat.com"
let s3o_ct = (show $ BS.unpack $ Web.fileContentType fi)
let s3o_data = Web.fileContent fi
 
rq <- sendObject awsConn $ S3Object {
obj_bucket = s3o_bucket,
obj_name = ("images/" ++ uid ++ "/" ++ filename),
content_type = s3o_ct,
obj_headers = [("acl","public-read")],
obj_data = s3o_data }
dbg $ "From AWS: " ++ (show rq)
sendRaw "success"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.