AWS Returning same ETAG for multipart upload

0

Hi, I am trying to upload a file in chunks to AWS but i am receiving same ETAG for different file chunks causing multipart file upload to fail. Here is my code

1.Javascript--Splitting the file into chunks

function splitFileIntoChunks(file: any) {
  const fileChunks: any[] = [];
  const partSize = 6 * 1024 * 1024; // 6 MB
  let offset = 0;
  while (offset < file.size) {
    const chunk = file.slice(offset, offset + partSize);
    fileChunks.push(chunk);
    offset += partSize;
  }
  return fileChunks;
}

2.Upload to Aspnet WebAPI using javascript

function uploadFileParts(chunks: any, part: number) {
  if (chunks.length == 0) {
    finalizeMultiPartUpload();
    return;
  }
  let chunk = chunks.shift();
  console.log('chunk', chunk);
  console.log('chunks', chunks);

  var FD = new FormData();
  FD.append('file', chunk);
  var xhr = new XMLHttpRequest();
  xhr.open('POST', `${environmentConstants['api_endpoints']['service']['baseUrl']}${url}/multipartupload/v1`, true);
  xhr.onload = function (a) {

    setTimeout(function () {
      uploadFileParts(chunks, (part + 1));
    }, 2000);
  };
  xhr.onerror = function () {
  };
  //xhr.setRequestHeader('uid', file['subject']);
  //xhr.setRequestHeader('Authorization', `Bearer ${file['token']}`);
  xhr.setRequestHeader('Multipart-key', requestKey);
  xhr.setRequestHeader('Multipart-uploadid', uploadId);
  xhr.setRequestHeader('Partnumber', `${part}`);
  xhr.send(FD);
}
  1. AspNet WebAPI Method
   public UploadPartResponse UploadPart(string bucket, string key, string uploadId, int partNumber, Stream currentStream, int size)
        {
            UploadPartRequest uploadRequest = new UploadPartRequest
            {
                BucketName = bucket,
                Key = key,
                UploadId = uploadId, // Use the uploadId from the initiation step
                PartNumber = partNumber,
                InputStream = currentStream,
                PartSize = size // The actual size of the part
            };
            using (var s3Client = new AmazonS3Client(accessKey, secretKey, Amazon.RegionEndpoint.EUWest1))
            {
                var uploadPartResponse = s3Client.UploadPart(uploadRequest);
                return new UploadPartResponse
                {
                    ETag = uploadPartResponse.ETag
                };
            }
        }

Inside UploadPart I am receiving Same ETag for different file chunks. please review and suggest changes.Thankyou

asked 8 months ago113 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions