Sure thing, I used it in this project: https://github.com/mcordova47/payback.
Here are the relevant snippets:
Main.elm > update:
UploadFile file ->
( { model | dragging = False }, Ports.upload file )
Decoder:
dropEventDecoder : Decoder Value
dropEventDecoder =
Decode.at [ "dataTransfer", "files", "0" ] Decode.value
File Drag/Drop Element:
fileDrop : Maybe String -> Bool -> Html Msg
fileDrop message dragging =
Html.div
[ Events.onWithOptions "drop"
{ stopPropagation = False, preventDefault = True }
(Decode.map UploadFile dropEventDecoder)
Ports.elm:
port upload : Value -> Cmd msg
index.js:
app.ports.upload.subscribe(file => {
const fileReader = new FileReader()
fileReader.onload = () => app.ports.readFile.send(fileReader.result)
fileReader.readAsText(file)
})