Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete multipart upload gets call before uploading particular part #7

Open
vijaykholiya opened this issue Mar 20, 2020 · 0 comments

Comments

@vijaykholiya
Copy link

I have used your code as a reference for multi part upload and the problem I am facing is my complete multipart upload gets executed before my any one part of the file starts upload.
I have created a for loop inside which i am initializing partnumber, partSizeToupload, dataToUpload, and position. Then API call to my backend server in Django to get presigned URL and when the API successfully gets called PUT call to upload that object.
My complete multipart upload API call is outside my for loop and on debugging I get to know it gets executed my for loop is executing.
Below is my code to do this task:
const partSize = 1024 * 1024 * 5;
const wavSize = wav.byteLength;
const partCount = parseInt(Math.ceil(wavSize / parseFloat(partSize, 10)), 10);
// let fileData = {};
let partNum = 0;
let position = 0;
let iterator = 0;
const uploadPartsArray = [];
let promisesArray = [];
for ( iterator = 0; iterator < partCount; iterator++) {
partNum = iterator + 1;
const partSizeToUpload = Math.min(partSize, (wavSize - position));
const dataToUpload = wav.slice(position, partSizeToUpload);
position = position + partSizeToUpload;

            apiService.uploadFilePart(this.props.meetingData.meeting.uuid, { upload_id: responseUrl.data.upload_id, key: responseUrl.data.file_key, file_part_number: partNum})
              .then((responseUploadPart) => {
                console.log('I am response from uploadFIlePart: ', responseUploadPart);
                const uploadRespPromise = apiService.uploadAudioRecording(responseUploadPart.data.url, dataToUpload, { headers: {'Access-Control-Expose-Headers': '*'} })
                  .then((responseUpload) => {
                    console.log('Upload AUdio iam response headers: ', responseUpload.headers.etag);
                    uploadPartsArray.push({
                      ETag: responseUpload.headers.etag,
                      PartNumber: partNum
                    });
                    console.log('Upload parts array: ', uploadPartsArray);
                  }).catch(error => { console.log('Error in uploading to presigned URL..', error); });

                promisesArray.push(uploadRespPromise);
              }).catch(error => { console.log('Error in API call of uploadFIlepart..', error);});
          }
          // Complete Multi part upload
          const resolvedArray = await Promise.all(promisesArray);
          console.log(resolvedArray, ' resolvedArray');
          console.log('Final Upload parts array: ', uploadPartsArray);
          apiService.completeMultipartUpload(this.props.meetingData.meeting.uuid, { upload_id: responseUrl.data.upload_id, key: responseUrl.data.file_key, file_parts: uploadPartsArray })
            .then((responseCompleteMltipart) => {
              console.log('Multi part upload response: ', responseCompleteMltipart);
            })
            .catch((errCMU) => { console.log('Error in completing multipart upload..,', errCMU); } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant