Bindings for the HTML5 file upload control, which is implemented in browsers via the native FileReader
class.
FileReader has three main methods (see MDN):
FileReaderInstance.readAsText();
FileReaderInstance.readAsArrayBuffer();
FileReaderInstance.readAsDataURL();
The module also provides helper Elm decoders for change
events on <Input type="file">
and drop
events, together with a set of examples.
New for Elm 0.18: An additional native code function has been added to enable multipart form uploads of binary data - see http://simonh1000.github.io/2016/12/elm-s3-uploads/
(sudo) gem install elm_install
<add "simonh1000/file-reader": "1.0.0 <= v < 2.0.0" to the dependencies section of elm-package.json>
elm-install
A great tool to install native-code based Elm libraries
Note in particular that you need to add "native-modules": true,
to your elm-package.json file as is done in the examples.
If you want to try the examples, you will need to edit src/Native/FileReader.js to replace the comments in the first two lines.
This project began in the time of 0.16 and was submitted as a library including NativeCode to the elm-package manager. It was never OKed, as was the case with all native code at that time. The native code was subsequently updated by WangBoxue to work with 0.17, and can be used as such. In theory Evan plans to make all browser web APIs available to Elm users and when that includes FileReader, this library will remove the native code.
In the meantime, note that the official guidance would be to use a port rather than a native library such as this. However, you will see that the native code covers the absolute minimum to expose the APIs so I believe this will not jeopardise the stability of your Elm apps.
Simon Hampton, Daniel Bachler