Last active
December 20, 2015 15:39
-
-
Save mikekunze/6155928 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
handler = ()-> | |
document.getElementById("fileField").files | |
# Make sure a file is selected first | |
if files.length <= 0 | |
alert('choose a file, first') | |
return | |
file = files[0] | |
fd = new FormData() | |
fd.append("fileForm", file) | |
xhr = new XMLHttpRequest() | |
# define our finish fn | |
loaded = ()-> | |
alert('finished uploading') | |
$("#addFile").one "click", handler | |
xhr.addEventListener 'load', loaded, false | |
# add progress indicator | |
xhr.upload.onprogress = (e)-> | |
percent = Math.round((e.loaded * 100) / e.total) | |
$("#progress").width "#{percent}%" | |
$("#progressDisplay").html "#{percent}%" | |
xhr.open "post", "/mUpload" | |
xhr.send fd | |
$(document).onReady ()-> | |
$("#addFile").one "click", handler | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment