title: Checksum did not match data received error on uploading large file in parts using b2 backblaze native php API
body: <p>I am using the following documentation for calling the Backblaze B2 API from PHP: <a href="https://www.backblaze.com/b2/docs/b2_upload_part.html" rel="nofollow noreferrer">https://www.backblaze.com/b2/docs/b2_upload_part.html</a></p>
  <p>Which has the code below:</p>
  <pre><code>&lt;?php
  
      // Used by curl when CURLOPT_READFUNCTION is set
      function myReadFile($curl_rsrc, $file_pointer, $length) {
          return fread($file_pointer, $length);
      }
  
      // Upload parts
      $minimum_part_size = 100 * (1000 * 1000); // Obtained from b2_authorize_account. The default is 100 MB
      $local_file = &quot;&lt;path to large file&gt;&quot;;
      $local_file_size = filesize($local_file);
      $total_bytes_sent = 0;
      $bytes_sent_for_part = 0;
      $bytes_sent_for_part = $minimum_part_size;
      $sha1_of_parts = Array();
      $part_no = 1;
      $file_handle = fopen($local_file, &quot;r&quot;);
      while($total_bytes_sent &lt; $local_file_size) {
  
          // Determine the number of bytes to send based on the minimum part size 
          if (($local_file_size - $total_bytes_sent) &lt; $minimum_part_size) {
              $bytes_sent_for_part = ($local_file_size - $total_bytes_sent);
         }
  
          // Get a sha1 of the part we are going to send  
          fseek($file_handle, $total_bytes_sent);
          $data_part = fread($file_handle, $bytes_sent_for_part);
          array_push($sha1_of_parts, sha1($data_part));
          fseek($file_handle, $total_bytes_sent);
  
          // Send it over th wire
          $session = curl_init($upload_url);
          // Add headers
          $headers = array();
          $headers[] = &quot;Accept: application/json&quot;;
          $headers[] = &quot;Authorization: &quot; . $large_file_auth_token;
          $headers[] = &quot;Content-Length: &quot; . $bytes_sent_for_part;
          $headers[] = &quot;X-Bz-Part-Number: &quot; . $part_no;
          $headers[] = &quot;X-Bz-Content-Sha1: &quot; . $sha1_of_parts[$part_no - 1];
          curl_setopt($session, CURLOPT_POST, true);
          curl_setopt($session, CURLOPT_HTTPHEADER, $headers);  // Add headers
          curl_setopt($session, CURLOPT_INFILE, $file_handle);
          curl_setopt($session, CURLOPT_INFILESIZE, (int)$bytes_sent_for_part);
          curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Receive server response
          curl_setopt($session, CURLOPT_READFUNCTION, &quot;myReadFile&quot;);
          $server_output = curl_exec($session);
          curl_close ($session);
          print $server_output . &quot;\n&quot;;    
  
          // Prepare for the next iteration of the loop
          $part_no++;
          $total_bytes_sent = $bytes_sent_for_part + $total_bytes_sent;
          $read_file_bytes_read = 0;
      }
      fclose($file_handle);
  
  ?&gt;
  </code></pre>
  <p>Which gives me the response:</p>
  <pre><code>{
      &quot;code&quot;: &quot;bad_request&quot;,
      &quot;message&quot;: &quot;Checksum did not match data received&quot;,
      &quot;status&quot;: 400
  }
  </code></pre>