Guest User

Untitled

a guest
May 25th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import Hack
  2. import qualified Web.Encodings as Web
  3. import Data.ByteString.Lazy.Char8 as BS
  4.  
  5. galleryDispatch ai@(\x -> head (pElements x) -> "u") =
  6. case requestMethod (a_env ai) of
  7. POST -> do
  8. dbg "galleryDispatch: POST on /upload."
  9. let env = a_env ai
  10. case ((,) <$> lookup "Content-Type" (http env)
  11. <*> lookup "Content-Length" (http env)) of
  12. Nothing -> do
  13. dbg "Ack!"
  14. redirect' "/profile"
  15. Just (ty,_len) -> do
  16. dbg $ "TY: " ++ (show ty)
  17. let bound = replace "boundary=" "" $ head $ drop 1 $ split " " ty
  18. dbg $ "Boundary: " ++ (show bound)
  19.  
  20. let uid = fromJust $ a_uid ai
  21. -- For testing, I'm just going to send one image
  22. let (_,[(a,fi)]) = Web.parseMultipart bound $ hackInput env
  23. dbg $ "a: " ++ (show $ BS.unpack a)
  24. dbg $ "Content-Type: " ++ (show $ BS.unpack $ Web.fileContentType fi)
  25. let filename = BS.unpack $ Web.fileName fi
  26. dbg $ "Filename: " ++ (show filename)
  27.  
  28. let s3o_bucket = "static.iplayedthat.com"
  29. let s3o_ct = (show $ BS.unpack $ Web.fileContentType fi)
  30. let s3o_data = Web.fileContent fi
  31.  
  32. rq <- sendObject awsConn $ S3Object {
  33. obj_bucket = s3o_bucket,
  34. obj_name = ("images/" ++ uid ++ "/" ++ filename),
  35. content_type = s3o_ct,
  36. obj_headers = [("acl","public-read")],
  37. obj_data = s3o_data }
  38. dbg $ "From AWS: " ++ (show rq)
  39. sendRaw "success"
Add Comment
Please, Sign In to add comment