import SparkMD5 from 'spark-md5' export default function getFilemd5sum(ofile) { return new Promise((resolve, reject) => { let file = ofile; let tmp_md5; let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice, // file = this.files[0], chunkSize = 8097152, // Read in chunks of 2MB chunks = Math.ceil(file.size / chunkSize), currentChunk = 0, spark = new SparkMD5.ArrayBuffer(), fileReader = new FileReader(); function loadNext() { var start = currentChunk * chunkSize, end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize; fileReader.readAsArrayBuffer(blobSlice.call(file, start, end)); } fileReader.onload = function (e) { spark.append(e.target.result); // Append array buffer currentChunk++; if (currentChunk < chunks) { loadNext(); } else { tmp_md5 = spark.end(); resolve(tmp_md5) } }; fileReader.onerror = function () { reject('error'); }; loadNext(); }) }