[Haskell-cafe] Happstack: moving the uploaded file
Tom Ellis
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Mon Jun 2 21:15:21 UTC 2014
On Tue, Jun 03, 2014 at 12:31:14AM +0400, Nikita Karetnikov wrote:
> I’d like the code to look like ‘UploadFile.hs’, but it doesn’t work
> properly. Could anyone explain why?
Yes, you can't receive the client's request containing the form data in the
reponse that sends out the form!
> tempFile :: ServerPart Response
> tempFile = do
> (tmpFile, _, _) <- lookFile "file_upload"
> liftIO $ renameFile tmpFile permFileLoc
> file <- liftIO $ readFile permFileLoc
> showFile file
>
> permFile :: ServerPart Response
> permFile = do
> file <- liftIO $ readFile permFileLoc
> showFile file
Why not merge these with something like (unchecked!)
readFile :: ServerPart Response
readFile = do
flip (<|>) (return ()) $ do
(tmpFile, _, _) <- lookFile "file_upload"
liftIO $ renameFile tmpFile permFileLoc
file <- liftIO $ readFile permFileLoc
showFile file
Tom
More information about the Haskell-Cafe
mailing list