Created
June 8, 2016 18:07
-
-
Save leobm/9b77feeb2035ff1372bf589ee7b2162d 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
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<form> | |
<!-- in firefox you can't choose a file diretory --> | |
<input type="file" id="file_input" directory webkitdirectory multiple /> | |
</form> | |
<script> | |
var fileInput = document.querySelector("#file_input"); | |
fileInput.onchange=function() { | |
var files = fileInput.files; | |
var filePaths = []; | |
for(i=0; i<files.length; i++) { | |
var file = files[i]; | |
filePaths.push(file.webkitRelativePath); | |
} | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', '/', true); | |
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); | |
xhr.onload = function(e) { | |
if (this.status == 200) { | |
console.log(this.response); | |
} | |
}; | |
xhr.send(JSON.stringify(filePaths)); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment