1 import qualified Data.ByteString.Lazy.Char8 as L8
3 import Network.HTTP.Lucu
6 main = let config = defaultConfig { cnfServerPort = "9999" }
7 resources = mkResTree [ ([], resMain) ]
9 do putStrLn "Access http://localhost:9999/ with your browser."
10 runHttpd config resources []
13 resMain :: ResourceDef
16 resUsesNativeThread = False
19 = Just $ do setContentType $ read "text/html"
20 output ("<title>Multipart Form Test</title>" ++
21 "<form action=\"/\" method=\"post\" enctype=\"multipart/form-data\">" ++
22 " Upload some file:" ++
23 " <input type=\"text\" name=\"text\">" ++
24 " <input type=\"file\" name=\"file\">" ++
25 " <input type=\"submit\" value=\"Submit\">" ++
29 = Just $ do form <- inputForm defaultLimit
30 let text = fromMaybe L8.empty $ fmap fdContent $ lookup "text" form
31 file = fromMaybe L8.empty $ fmap fdContent $ lookup "file" form
32 fileName = fdFileName =<< lookup "file" form
33 setContentType $ read "text/plain"
34 outputChunk ("You entered \"" ++ L8.unpack text ++ "\".\n")
35 outputChunk ("You uploaded a " ++ show (L8.length file) ++ " bytes long file.\n")
36 output ("The file name is " ++ show fileName ++ ".\n")