File Upload in Elm

后端 未结 4 1122
别那么骄傲
别那么骄傲 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:29

    The other option to handle file uploads in Elm is to

    • get a base64-encoded value from the FileReader into your Elm app through a port.
    • Then, send that base64-encoded value to your server (e.g. in a JSON body).

    A tutorial can be found here https://www.paramander.com/blog/using-ports-to-deal-with-files-in-elm-0-17 (it says it's for Elm 0.17, but it works unchanged in Elm 0.18).

    The downsides of this approach are

    • your server needs to base64-decode the files it receives which increases server load a little, and
    • base64-encoding increases the amount of bytes that will go over the wire (compared to a file/blob).

    The upside:

    • no need to use a package with native code.

    From the Elm Http docs: "Right now it only supports strings, but we will support blobs and files when we get an API for them in Elm."

提交回复
热议问题