I'm struggling to split a POST response (multipart) apart, what should be used to put the contents of some files sent to the Yesod server into a database (after some further processing). My current code:
import qualified Data.ByteString.Lazy as LZ
import qualified Data.ByteString.Lazy.Char8 as LC
...
processLines :: String -> [String] -> String
processLines delim (l:rest) = do
case l of
delim -> ""
_ -> l ++ "\n" ++ processLines delim rest
processFile :: [String] -> String
processFile (delim:some:other:line:txt) = processLines delim txt
postImpexR :: SystemsId -> Handler RepPlain
postImpexR sysid = do
wr <- waiRequest
bss <- lift $ requestBody wr $$ consume
let file = LZ.fromChunks bss
return $ RepPlain $ toContent $ processFile $ map LC.unpack $ LC.lines file
Edit: Managed to fix one problem, seems I'm on the way to understand handlers. What's the problem with the types here?? Is there a more elegant way to get this done than this?