main = mainWidget $
el "div" $ do
let fileInputConfig = FileInputConfig (constDyn Map.empty)
fi <- fileInput fileInputConfig
let uploads :: Dynamic t [File] = value fi
upload :: Dynamic t (Maybe File) <- (return . fmap headMay) uploads
getNameAction :: Dynamic t (Maybe (IO Text)) <- (return . fmap (getNameText <$>)) upload
filename :: Dynamic t (Maybe Text) <- (return . fmap (unsafePerformIO <$>)) getNameAction
el "div" $ dynText (show <$> filename)
return ()
where getNameText :: MonadIO m => File -> m Text
getNameText = getName
I did my best to play connect-the-dots with the types but I couldn't find a path out without using unsafePerformIO
. I think it's safe in this case, but obviously there are other similar things you might want to do that would not be safe.