html5大文件上传技术(四)

本文介绍了如何使用js-spark-md5库在前端计算文件MD5值,用于大文件上传时的校验。通过计算文件MD5并和服务器已有的文件进行比较,如果相同则避免重复上传,节省资源和时间。
摘要由CSDN通过智能技术生成

五、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 + "  正在
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值