Created
January 2, 2017 04:46
-
-
Save mightybyte/34bc917d038e8f954f0862f48518e46e to your computer and use it in GitHub Desktop.
Reflex file loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileLoader :: MonadWidget t m => FileInputConfig t -> m (Event t Text) | |
fileLoader cfg = do | |
fls <- fmapMaybe listToMaybe . updated . value <$> fileInput cfg | |
reader <- liftIO newFileReader | |
performEvent_ $ ffor fls $ \f -> liftIO $ | |
readAsDataURL reader (Just f) | |
wrapDomEvent reader (`on` load) $ do | |
res <- liftIO $ fromJSValUnchecked =<< getResult reader | |
let Right contents = decodeUtf8 <$> B64.decode | |
(encodeUtf8 $ snd $ T.breakOnEnd "base64," res) | |
return contents | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment