Awesome
Awesome

Reputation: 6609

How to calculate MD5 checksum of blob using JQuery

My requirement is to upload large files (upto 50GB) through browser. So I used JQuery file upload plugin to upload those large files in smaller chunks.

Now I have to calculate MD5 checksum for each chunk to avoid data corruption issues from browser to server.

Is there any plugin in JQuery to calculate checksum for the blob chunks except Google CryptoJS utility ?

Upvotes: 2

Views: 1580

Answers (1)

emn178
emn178

Reputation: 1492

You can try js-md5.

This is a online demo to get file checksum.

You can input arraybuffer like this

var total; // total file size
var batch = 1024 * 1024; // batch size
var start = 0;
var current = md5;
var asyncUpdate = function () {
  if (start < total) {
    var end = Math.min(start + batch, total);
    current = current.update(arrayBuffer.slice(start, end));
    start = end;
    setTimeout(asyncUpdate);
  } else {
    var hash = current.hex(); // result
  }
}
asyncUpdate();

Upvotes: 1

Related Questions