title: AWS SDK JS: Multipart upload to S3 resulting in Corrupt data
body: <p>Trying to upload an mp4 file using the AWS JS SDK initiating a multipart upload, I keep getting a file corrupt error when I try to download and play it on my local.</p>
  
  <p>Gists of my code: </p>
  
  <ol>
  <li><p>Initiating the multipart upload with params:</p>
  
  <pre><code>const createMultipartUploadParams = {
    Bucket: bucketname,
    Key: fileHash.file_name,
    ContentType: 'video/mp4' // TODO: Change hardcode
  };
  </code></pre></li>
  </ol>
  
  <p>Call: </p>
  
  <pre><code>s3Instance.createMultipartUpload(createMultipartUploadParams, function(err, data) {
  }
  </code></pre>
  
  <ol start="2">
  <li><p>Doing the chunking:
  Params: </p>
  
  <pre><code> const s3ChunkingParams = {
        chunkSize,
        noOfIterations,
        lastChunk ,
        UploadId: data.UploadId
   }
  </code></pre></li>
  </ol>
  
  <p>Reading the file:</p>
  
  <pre><code>     const reader = new FileReader();
       reader.readAsArrayBuffer(file)
  </code></pre>
  
  <p>Uploading each chunk:</p>
  
  <pre><code>        reader.onloadend = function onloadend(){
        console.log('onloadend');
        const partUploadParams = {
          Bucket: bucketname,
          Key: file_name,
          PartNumber: i, // Iterating over all parts
          UploadId: s3ChunkingParams.UploadId,
          Body: reader.result.slice(start, stop) // Chunking up the file
        };
  
        s3Instance.uploadPart(partUploadParams, function(err, data1) {
        }
  </code></pre>
  
  <ol start="3">
  <li><p>Finally completing the multipartUpload:</p>
  
  <p>s3Instance.completeMultipartUpload(completeMultipartParams, function(err, data)</p></li>
  </ol>
  
  <p>I am guessing the problem is how I am reading the file, so I have tried Content Encoding it to base64 but that makes the size unusually huge. Any help is greatly appreciated!</p>
  
  <p>Tried <a href="https://stackoverflow.com/questions/33248514/corrupt-truncated-mp4-upload-to-s3-bucket-using-nodejs-and-aws-s3">this too</a></p>