Skip to content

Instantly share code, notes, and snippets.

@nqthqn
Last active April 11, 2018 21:12
Show Gist options
  • Save nqthqn/6ef169ea9a2792c3150e7592158d8119 to your computer and use it in GitHub Desktop.
Save nqthqn/6ef169ea9a2792c3150e7592158d8119 to your computer and use it in GitHub Desktop.
File upload in elm
app.ports.upload.subscribe(function(pathIdToken) {
var [tasksrvPath, formId, token] = pathIdToken
try {
var fd = new FormData(document.getElementById(formId));
var r = new XMLHttpRequest()
r.open("POST", tasksrvPath, true)
r.setRequestHeader("Authorization", "Bearer " + token)
r.send(fd)
r.onload = function() {
app.ports.status.send(r.response)
}
} catch (e) {
console.log(e.message);
}
})
port upload : ( String, String, String ) -> Cmd msg
port status : (String -> msg) -> Sub msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment