0

I am trying to make a form in elm that would be able to upload a picture and some accompanying data.

Right now all my fields are updating my model via the onInput function, and I when I press the submit button I send my data as JSON via the Http.post function. If I understand well this is the idiomatic way of doing forms in elm.

Is there a way to add file uploading capabilities to this kind of form? If possible I would like to keep control in the elm app without resorting to the standard html elements to do submitting.

fayong lin
  • 214
  • 2
  • 15

2 Answers2

4

Yes, native code is needed for two things:

  • to access the FileReader API; and
  • to 'trick' the HTTP library into allowing you to add a file to a multipart form.

This is all covered in this blog post, which accompanies the FileReader library mentioned by rofol.

Instead of native code, you can of course use ports.

Andrew Gaul
  • 2,296
  • 1
  • 12
  • 19
Simon H
  • 20,332
  • 14
  • 71
  • 128