Kasey Speakman
2017-05-05 17:32:46 UTC
After a bit of research on file uploads, I pared it down to the simplest
method I could find. Here is the recipe I came up with.
https://gist.github.com/kspeakman/20708d5ff58b6ea75f9c3a82f6c793c3
The FileUtils module essentially wraps the JS File object in Http.Body as
well as exposing common file info (name, size, contentType). Using
Http.Body makes it quite easy to send files with normal Http calls.
Unfortunately this does use native/kernel code, but this made it far easier
to work with in Elm than if I used ports. I did actually try using decoders
first to pull in the "e.target.files" property as a Value, but Elm just
fails to decode it.
I also thought something like this could be a path forward to introduce
basic file uploads into Elm's core. It is not a general solution for all
binary formats. But it is a straightforward way to handle File objects from
JS.
method I could find. Here is the recipe I came up with.
https://gist.github.com/kspeakman/20708d5ff58b6ea75f9c3a82f6c793c3
The FileUtils module essentially wraps the JS File object in Http.Body as
well as exposing common file info (name, size, contentType). Using
Http.Body makes it quite easy to send files with normal Http calls.
Unfortunately this does use native/kernel code, but this made it far easier
to work with in Elm than if I used ports. I did actually try using decoders
first to pull in the "e.target.files" property as a Value, but Elm just
fails to decode it.
I also thought something like this could be a path forward to introduce
basic file uploads into Elm's core. It is not a general solution for all
binary formats. But it is a straightforward way to handle File objects from
JS.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.