Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Created January 2, 2017 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mightybyte/34bc917d038e8f954f0862f48518e46e to your computer and use it in GitHub Desktop.
Save mightybyte/34bc917d038e8f954f0862f48518e46e to your computer and use it in GitHub Desktop.
Reflex file loader
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