I tried using both:

import Json.Decode as Json

-- the first JS File
Json.at [ "target", "files" ] (Json.index 0 Json.value)

-- the JS FileList
Json.at [ "target", "files" ] Json.value

Both of which came back as undefined after decoding. Maybe I was doing 
something else wrong?

Even one of these came through as Value, you can't do anything with it in 
Elm. The Http module has no mechanism to send Value, only Strings 
(multi-part also takes only Strings). For security reasons, the only way to 
access the JS File contents (AFAIK) is through another JS API like XHR (to 
send) or FileReader (to read the contents). There has to be some native 
code involved to either get the contents or convert the file reference to 
something that Elm can use.

On Saturday, May 6, 2017 at 2:45:29 PM UTC-5, Witold Szczerba wrote:
>
> > 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.
>
> How did you try to decode the "files"? There is a special function:
> value -> Decoder Value
> it does leave the structure "as is". I was wandering if it could work? The 
> original "files" could be then assigned to the body, so Elm would not touch 
> it at all. Would it possibly work?
>
> Regards,
> Witold Szczerba
>
> 05.05.2017 7:32 PM "Kasey Speakman" <[email protected] <javascript:>> 
> napisaƂ(a):
>
>> 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.
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to