title: How to get md5 iterated md5 sum of every chunk, using blueimp jquery upload plugin
body: <p>I need to calculate and send an iterated md5-hash to my upload-api.
  But I don't know how.</p>
  
  <p>I´m using the tutorial found here:</p>
  
  <blockquote>
    <p><a href="http://tutorialzine.com/2013/05/mini-ajax-file-upload-form/" rel="nofollow noreferrer">http://tutorialzine.com/2013/05/mini-ajax-file-upload-form/</a></p>
  </blockquote>
  
  <p>Along with the <strong>blueimp</strong> jquery upload plugin.</p>
  
  <p>For sending only ONE FILE (file size smaller than chunk size), everything is working fine. But if a file is chunked, then I have no idea, how to catch the chunk to get md5 of it.</p>
  
  <p>At the end I have to make the md5 iteratively like described here:</p>
  
  <blockquote>
    <p><a href="https://code.google.com/p/crypto-js/#Progressive_Hashing" rel="nofollow noreferrer">https://code.google.com/p/crypto-js/#Progressive_Hashing</a></p>
  </blockquote>
  
  <pre><code>$('#upload').fileupload({
  
      // This element will accept file drag/drop uploading
      dropZone: $('#drop'),
  
      type        : GLOBAL_FORM_METHOD,
      method      : "post",   // Type of data-send-method
      dataType    : "json",   // Type of data to recieve from api-call
      maxChunkSize: GLOBAL_CHUNK_SIZE,
      multipart   : true,
  
      // This function is called when a file is added to the queue;
      // either via the browse button, or via drag/drop:
      add: function (e, data)
      {
          var reader = new FileReader();
          var file = data.files[0];
          var jqXHR;
  
          var tpl = $('&lt;li class="working"&gt;&lt;input type="text" value="0" data-width="48" data-height="48"'+
              ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="msg"&gt;&lt;/div&gt;&lt;span&gt;&lt;/span&gt;&lt;/li&gt;');
  
          // Append the file name and file size
          tpl.find('p')
              .text( file.name )
              .append('&lt;i&gt;' + formatFileSize( file.size ) + '&lt;/i&gt;');
  
          // Add the HTML to the UL element
          data.context = tpl.appendTo(ul);
  
          // Initialize the knob plugin
          tpl.find('input').knob();
  
          // Listen for clicks on the cancel icon
          tpl.find('span').click(function()
          {
              if( tpl.hasClass('working') )
              {
                  jqXHR.abort();
              }
  
              tpl.fadeOut( function()
              {
                  tpl.remove();
              });
          });
  
          // Prevent XHR from sending data in "multipart/formData"
          data.postMessage = data.files[0].type;
          data.contentType = data.files[0].type;
  
          var chunksize = GLOBAL_CHUNK_SIZE &gt; file.size ? file.size : GLOBAL_CHUNK_SIZE;
  
          // Describe the FileReader-DataLoad-Event
          reader.onload = function( event ) 
          {
              var binary = event.target.result;
              var md5 = CryptoJS.MD5(binary).toString();
  
              data.url += "&amp;md5sum=" + md5;
  
              // D A T A   S E N D 
              jqXHR = data.submit();
          };
  
          // ADD url to XHR-object
          data.url = GLOBAL_FORM_ACTION;
          data.url += "?etf_id=" + GLOBAL_FOLDER_ID;
          data.url += "&amp;file_title=" + file.name;
  
          // If the file will be send in one piece...
          if( GLOBAL_CHUNK_SIZE &gt; file.size )
          {
              // ADD url-parameter to XHR-object
              data.url += "&amp;size_chunk_start=" + 0;
              data.url += "&amp;size_chunk_length=" + chunksize;
          }
          // This part for the chunks must be in "beforeSend"-Callback,
          // because, the chunk-related size-data is undefined in this case
          // but available there.
  
          // ADD url-parameter to XHR-object
          data.url += "&amp;size_final=" + file.size;
  
          // Read md5-sum and send the file / chunk...
          // On multipart "file" is a chunk !
          reader.readAsBinaryString( file );
      },
  
      beforeSend : function(e, data)
      {
          var file = data.files[0];
  
          this.find(".msg").hide();
  
          // If the file will be send as chunks...
          if( GLOBAL_CHUNK_SIZE &lt; file.size )
          {
              console.log( "Chunk data: ", data.uploadedBytes, data.chunkSize, file.size, data );
  
              // ADD url-parameter to XHR-object
              data.url += "&amp;size_chunk_start=" + data.uploadedBytes;
              data.url += "&amp;size_chunk_length=" + data.chunkSize;
  
              if( typeof this.attr('session_id') !== "undefined" )
                  data.url += "&amp;session_id=" + this.attr( 'session_id' );
          }
  
      });
  </code></pre>
  
  <p>I hope you help, so that I can myself solve this.</p>