Last active
April 11, 2018 21:12
-
-
Save nqthqn/6ef169ea9a2792c3150e7592158d8119 to your computer and use it in GitHub Desktop.
File upload in elm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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