Created
May 17, 2010 09:16
-
-
Save cmoore/403570 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
{- No, it's not live. Just testing. :) -} | |
{-# LANGUAGE ViewPatterns #-} | |
galleryDispatch ai@(\x -> head (pElements x) -> "u") = | |
case requestMethod (a_env ai) of | |
POST -> do | |
let env = a_env ai -- Hack's Env | |
case ((,) <$> lookup "Content-Type" (http env) | |
<*> lookup "Content-Length" (http env)) of | |
Nothing -> do | |
dbg "Ack!" | |
redirect' "/profile" | |
Just (ty,_len) -> do | |
let bound = head $ drop 1 $ split " " ty | |
dbg $ "Boundary: " ++ bound | |
let (_,[(_,fi)]) = Web.parseMultipart bound $ RQ.body env | |
let content = Web.fileContent fi | |
dbg $ "fi length: " ++ (show $ BS.length content) | |
_ <- BS.writeFile ("public/images/test/" ++ (BS.unpack $ Web.fileName fi)) $ Web.fileContent fi | |
sendRaw "success" | |
_ -> do | |
dbg $ "galleryDispatch: upload that isn't a POST." | |
redirect' "/gallery" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment