norpan/elm-file-reader/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

FileReader

This module exposes attributes that you can use to read files into Elm.

type alias File =
{ lastModified : Maybe Time
, name : String
, size : Int
, mimeType : String
, dataURL : String
}

A selected file that has been read into the application. The file contents are in the form of a data URL as specified by RFC 2397.

lastModified is of type Maybe Time because not all browsers and situations will give you a last modified field.

fileInput : (File -> msg) -> List (Attribute msg)

Add these attributes to an input node to get the contents of the selected file.

type Msg
    = FileSelected File


view =
    Html.input (fileInput FileSelected) []
filesInput : (List File -> msg) -> List (Attribute msg)

Add these attributes to an input node to get the contents of the selected files.

type Msg
    = FilesSelected (List File)


view =
    Html.input (filesInput FilesSelected) []
{ enterMsg : msg
, leaveMsg : msg
, filesMsg : List File -> msg
}
-> List (Attribute msg)

Add these attributes to any node to create a "drop zone" for files and get the contents of the dropped files. The enterMsg and leaveMsg messages could be used to visually indicate the drop zone.

You will either get a leaveMsg or a filesMsg, so make sure the filesMsg also clears any visual indication started by the enterMsg.

type Msg
    = EnterDropZone
    | LeaveDropZone
    | FilesDropped (List File)


view =
    Html.div
        (dropZone
            { enterMsg = EnterDropZone
            , leaveMsg = LeaveDropZone
            , filesMsg = FilesDropped
            }
        )
        [ Html.text "Drop files here" ]