main :: IO ()
main = scotty 3000 $ do
    middleware logStdoutDev
    middleware $ staticPolicy (noDots >-> addBase "uploads")

    get "/" $
      html $ renderHtml
             $ H.html $
                H.body $
                    H.form H.! method "post" H.! enctype "multipart/form-data" H.! action "/upload" $ do
                        H.input H.! type_ "file" H.! name "foofile"
                        H.br
                        H.input H.! type_ "file" H.! name "barfile"
                        H.br
                        H.input H.! type_ "submit"

    post "/upload" $ do
        fs <- files
        let fs' = [ (fieldName, BS.unpack (fileName fi), fileContent fi) | (fieldName,fi) <- fs ]
        -- write the files to disk, so they will be served by the static middleware
        liftIO $ sequence_ [ B.writeFile ("uploads" </> fn) fc | (_,fn,fc) <- fs' ]
        -- generate list of links to the files just uploaded
        html $ mconcat [ mconcat [ fName
                                 , ": "
                                 , renderHtml $ H.a (H.toHtml fn) H.! href (H.toValue fn) >> H.br
                                 ]
                       | (fName,fn,_) <- fs' ]
main :: IO ()
main = scotty 3000 $ do
    middleware logStdoutDev
    middleware $ staticPolicy (noDots >-> addBase "uploads")

    get "/" $
      html $ renderHtml
             $ H.html $
                H.body $
                    H.form H.! method "post" H.! enctype "multipart/form-data" H.! action "/upload" $ do
                        H.input H.! type_ "file" H.! name "foofile"
                        H.br
                        H.input H.! type_ "file" H.! name "barfile"
                        H.br
                        H.input H.! type_ "submit"

    post "/upload" $ do
        fs <- files
        let fs' = [ (fieldName, BS.unpack (fileName fi), fileContent fi) | (fieldName,fi) <- fs ]
        -- write the files to disk, so they will be served by the static middleware
        liftIO $ sequence_ [ B.writeFile ("uploads" </> fn) fc | (_,fn,fc) <- fs' ]
        -- generate list of links to the files just uploaded
        html $ mconcat [ mconcat [ fName
                                 , ": "
                                 , renderHtml $ H.a (H.toHtml fn) H.! href (H.toValue fn) >> H.br
                                 ]
                       | (fName,fn,_) <- fs' ]
main = scotty 3000 $ do
    middleware logStdoutDev
    middleware $ staticPolicy (noDots >-> addBase "uploads")

    get "/" $
      html $ renderHtml
             $ H.html $
                H.body $
                    H.form H.! method "post" H.! enctype "multipart/form-data" H.! action "/upload" $ do
                        H.input H.! type_ "file" H.! name "foofile"
                        H.br
                        H.input H.! type_ "file" H.! name "barfile"
                        H.br
                        H.input H.! type_ "submit"

    post "/upload" $ do
        fs <- files
        let fs' = [ (fieldName, BS.unpack (fileName fi), fileContent fi) | (fieldName,fi) <- fs ]
        -- write the files to disk, so they will be served by the static middleware
        liftIO $ sequence_ [ B.writeFile ("uploads" </> fn) fc | (_,fn,fc) <- fs' ]
        -- generate list of links to the files just uploaded
        html $ mconcat [ mconcat [ fName
                                 , ": "
                                 , renderHtml $ H.a (H.toHtml fn) H.! href (H.toValue fn) >> H.br
                                 ]
                       | (fName,fn,_) <- fs' ]