Search code examples
azuremd5fine-uploader

How to include Content-MD5 header in FineUploader Azure request?


I would like to use the Content-MD5 header to supply Azure with a client-side generated MD5 hash of the files being uploaded. How would I accomplish this task in FineUploader?

Target audience: Firefox, Chrome, Safari, Opera and IE10+.

Judging by this answer I gather that it should be possible but at least half of our clients will run on very old (slow) computers. Is it feasible to do this client side MD5 hashing approach then?

Somewhat related side question: I was also thinking that it might be wise to set a maximum file size to reduce strain on the MD5 hashing algorithm. Maybe just below Azure's "chunking" limit? From a different view: Can I disable chunking?


Solution

  • Fine Uploader provides direct access to the underlying File or Blob object via the getFile(id) API method. Once you have access to this, you can make use of FileReader to read the file/blob bytes and generate a hash. To make hashing even easier, consider using a JS library like SparkMD5.

    The best place to calculate this hash is probably in an onSubmit callback handler. Since the process of reading a file is asynchronous, you will have to return a promise in your handler, which is supported by Fine Uploader. Once the hash has been calculated, resolve the promise and set the hash as a parameter for the file using Fine Uploader's setParams API method.

    Can I disable chunking?

    Yes, you can, but you will lose all of the benefits associated with chunking, along with the resume feature and efficient retries should the file upload fail midway though.