File Upload in Elm

后端 未结 4 1109
别那么骄傲
别那么骄傲 2020-12-10 01:31

How does one upload a file (image or excel) in Elm?

Can\'t seem to find any examples.

The answer is fine even if the native code is used. Have seen Da

4条回答
  •  自闭症患者
    2020-12-10 02:09

    The official way to do it is now https://package.elm-lang.org/packages/elm/file/latest/

    This is an addition that came in Elm 0.19.

    Now the official Http package supports it as well. Here is an example from https://package.elm-lang.org/packages/elm/http/latest/Http#request

    import File
    import Http
    
    type Msg = Uploaded (Result Http.Error ())
    
    upload : File.File -> Cmd Msg
    upload file =
      Http.request
        { method = "PUT"
        , headers = []
        , url = "https://example.com/publish"
        , body = Http.fileBody file
        , expect = Http.expectWhatever Uploaded
        , timeout = Nothing
        , tracker = Nothing
        }
    

提交回复
热议问题