5 import qualified Data.ByteString.Lazy.Char8 as Lazy
6 import Control.Applicative
7 import qualified Data.Collections as C
8 import Control.Monad.Unicode
10 import Data.Monoid.Unicode
11 import Network.HTTP.Lucu
14 main = let config = defaultConfig { cnfServerPort = "9999" }
16 tree = C.fromList [ ([], nonGreedy resMain) ]
18 do putStrLn "Access http://localhost:9999/ with your browser."
19 runHttpd config $ resourceMap tree
24 , do setContentType $ parseMIMEType "text/html"
25 putChunks $ "<title>Multipart Form Test</title>\n"
26 ⊕ "<form action=\"/\" method=\"post\" enctype=\"multipart/form-data\">\n"
27 ⊕ " Upload some file:\n"
28 ⊕ " <input type=\"text\" name=\"text\">\n"
29 ⊕ " <input type=\"file\" name=\"file\">\n"
30 ⊕ " <input type=\"submit\" value=\"Submit\">\n"
34 , do form ← getForm Nothing
35 let text = fromMaybe (∅) $ fdContent <$> lookup "text" form
36 file = fromMaybe (∅) $ fdContent <$> lookup "file" form
37 fileName = fdFileName =≪ lookup "file" form
38 setContentType $ parseMIMEType "text/plain"
39 putChunks $ "You entered \"" ⊕ text ⊕ "\".\n"
40 putChunks $ "You uploaded a " ⊕ Lazy.pack (show $ Lazy.length file) ⊕ " bytes long file.\n"
41 putChunks $ "The file name is " ⊕ Lazy.pack (show fileName) ⊕ ".\n"