Created
January 11, 2013 12:28
-
-
Save ashwoods/4510319 to your computer and use it in GitHub Desktop.
calculating md5 from file.api
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
<html> | |
<head> | |
<title>HTML5 File example</title> | |
<STYLE TYPE="text/css"> | |
<!-- | |
TD{font-family: Arial, Helvetica, sans-serif; font-size: 8pt;} | |
---> | |
</STYLE> | |
<style>.example{padding:10px;border:1px solid #ccc}#drop_zone{border:2px dashed #bbb;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;padding:25px;text-align:center;font:20pt bold,"Vollkorn";color:#bbb}.thumb{height:75px;border:1px solid #000;margin:10px 5px 0 0}#progress_bar{margin:10px 0;padding:3px;border:1px solid #000;font-size:14px;clear:both;opacity:0;-o-transition:opacity 1s linear;-moz-transition:opacity 1s linear;-webkit-transition:opacity 1s linear;-ms-transition:opacity 1s linear}#progress_bar.loading{opacity:1}#progress_bar .percent{background-color:#9cf;height:auto;width:0}#byte_content{margin:5px 0;max-height:100px;overflow-y:auto;overflow-x:hidden}#byte_range{margin-top:5px}</style> | |
<script src="http://www.myersdaily.org/joseph/javascript/md5.js"></script> | |
<div id="drop_zone">Drop files here</div> | |
<output id="list"></output> | |
<script> | |
function handleFileSelect(evt) { | |
evt.stopPropagation(); | |
evt.preventDefault(); | |
var files = evt.dataTransfer.files; // FileList object. | |
// files is a FileList of File objects. List some properties. | |
var output = []; | |
for (var i = 0, f; f = files[i]; i++) { | |
output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ', | |
f.size, ' bytes, last modified: ', | |
f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a', | |
'</li>'); | |
var reader = new FileReader(); | |
reader.onloadend = function(evt) { | |
if (evt.target.readyState == FileReader.DONE) { // DONE == 2 | |
console.log(md5(evt.target.result)) | |
} | |
}; | |
reader.readAsBinaryString(f); | |
} | |
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>'; | |
} | |
function handleDragOver(evt) { | |
evt.stopPropagation(); | |
evt.preventDefault(); | |
evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. | |
} | |
// Setup the dnd listeners. | |
var dropZone = document.getElementById('drop_zone'); | |
dropZone.addEventListener('dragover', handleDragOver, false); | |
dropZone.addEventListener('drop', handleFileSelect, false); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment