五、MD5文件校验
基于js-spark-md5前端js类库,可快速获取文件Md5值,点击下载:spark-md5.js
一个分片读取大文件MD5值得范例(引用)
<body> <div>
<div>
添加文件
<input type="file" name="" id="fileinput">
</div>
<progress class='progressbar' value="0" max="100" style='width:500px;margin-top:20px'></progress>
<div style='margin-top:20px'>
<span id="handler_info" ></span>
</div>
</div>
<script src="Scripts/spark-md5.js"></script>
<script>
function get_filemd5sum(ofile) {
var file = ofile;
var tmp_md5;
var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
// file = this.files[0],
chunkSize = 2 * 1024 * 1024, // Read in chunks of 2MB
chunks = Math.ceil(file.size / chunkSize),
currentChunk = 0,
spark = new SparkMD5.ArrayBuffer(),
fileReader = new FileReader();
fileReader.onload = function(e) {
// console.log('read chunk nr', currentChunk + 1, 'of', chunks);
spark.append(e.target.result); // Append array buffer
currentChunk++;
var md5_progress = Math.floor((currentChunk / chunks) * 100);
console.log(file.name + " 正在