I've seen simple ways to read contents from a file input in JavaScript using HTML5 File API.
This is my view method, inside a small fable-arch app:
let view model =
div [
attribute "class" "files-form"
] [
form [
attribute "enctype" "multipart/form-data"
attribute "action" "/feed"
attribute "method" "post"
] [
label [ attribute "for" "x_train" ] [ text "Training Features" ]
input [
attribute "id" "x_train"
attribute "type" "file"
onInput (fun e -> SetTrainingFeaturesFile (unbox e?target?value))
]
]
model |> sprintf "%A" |> text
]
- Is there a simple way to capture the file content directly from F#?
- What is the minimum amount of interop fable code necessary to accomplish this?
In the latest version of Fable, we now have access to
Browser.Dom.FileReaderand avoid using interop.It is possible to write something like:
Live demo