Skip to content

Instantly share code, notes, and snippets.

@leobm
Created June 8, 2016 18:07
Show Gist options
  • Save leobm/9b77feeb2035ff1372bf589ee7b2162d to your computer and use it in GitHub Desktop.
Save leobm/9b77feeb2035ff1372bf589ee7b2162d to your computer and use it in GitHub Desktop.
<!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