Created
May 17, 2010 23:01
-
-
Save cmoore/404346 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
import Hack | |
import qualified Web.Encodings as Web | |
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) | |
-- For testing, I'm just going to send one image | |
let (_,[(x,fi)]) = Web.parseMultipart bound $ hackInput env | |
dbg $ "X: " ++ (show $ BS.unpack x) | |
_ <- BS.writeFile ("public/images/test/" ++ (BS.unpack $ Web.fileName fi)) $ Web.fileContent fi | |
sendRaw "success" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment