@aws-amplify/storage 4.4.23 → 4.4.24-unstable.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49533,7 +49533,7 @@ function () {
49533
49533
  this.params = null;
49534
49534
  this.opts = null;
49535
49535
  this.completedParts = [];
49536
- this.cancel = false; // Progress reporting
49536
+ this.uploadId = null; // Progress reporting
49537
49537
 
49538
49538
  this.bytesUploaded = 0;
49539
49539
  this.totalBytesToUpload = 0;
@@ -49546,20 +49546,22 @@ function () {
49546
49546
 
49547
49547
  AWSS3ProviderManagedUpload.prototype.upload = function () {
49548
49548
  return __awaiter(this, void 0, void 0, function () {
49549
- var _a, putObjectCommand, uploadId, numberOfPartsToUpload, parts, start;
49549
+ var _a, putObjectCommand, _b, numberOfPartsToUpload, parts, start, error_1;
49550
49550
 
49551
49551
  var _this = this;
49552
49552
 
49553
- return __generator(this, function (_b) {
49554
- switch (_b.label) {
49553
+ return __generator(this, function (_c) {
49554
+ switch (_c.label) {
49555
49555
  case 0:
49556
+ _c.trys.push([0, 10,, 12]);
49557
+
49556
49558
  _a = this;
49557
49559
  return [4
49558
49560
  /*yield*/
49559
49561
  , this.validateAndSanitizeBody(this.params.Body)];
49560
49562
 
49561
49563
  case 1:
49562
- _a.body = _b.sent();
49564
+ _a.body = _c.sent();
49563
49565
  this.totalBytesToUpload = this.byteLength(this.body);
49564
49566
  if (!(this.totalBytesToUpload <= this.minPartSize)) return [3
49565
49567
  /*break*/
@@ -49572,107 +49574,113 @@ function () {
49572
49574
  , this.s3client.send(putObjectCommand)];
49573
49575
 
49574
49576
  case 2:
49577
+ // Step 1: Initiate the multi part upload
49578
+ _b = this;
49575
49579
  return [4
49576
49580
  /*yield*/
49577
49581
  , this.createMultiPartUpload()];
49578
49582
 
49579
49583
  case 3:
49580
- uploadId = _b.sent();
49584
+ // Step 1: Initiate the multi part upload
49585
+ _b.uploadId = _c.sent();
49581
49586
  numberOfPartsToUpload = Math.ceil(this.totalBytesToUpload / this.minPartSize);
49582
49587
  parts = this.createParts();
49583
49588
  start = 0;
49584
- _b.label = 4;
49589
+ _c.label = 4;
49585
49590
 
49586
49591
  case 4:
49587
49592
  if (!(start < numberOfPartsToUpload)) return [3
49588
49593
  /*break*/
49589
- , 9];
49590
- /** This first block will try to cancel the upload if the cancel
49591
- * request came before any parts uploads have started.
49592
- **/
49594
+ , 7]; // Upload as many as `queueSize` parts simultaneously
49593
49595
 
49594
49596
  return [4
49595
49597
  /*yield*/
49596
- , this.checkIfUploadCancelled(uploadId)];
49598
+ , this.uploadParts(this.uploadId, parts.slice(start, start + this.queueSize))];
49597
49599
 
49598
49600
  case 5:
49599
- /** This first block will try to cancel the upload if the cancel
49600
- * request came before any parts uploads have started.
49601
- **/
49602
- _b.sent(); // Upload as many as `queueSize` parts simultaneously
49603
-
49604
-
49605
- return [4
49606
- /*yield*/
49607
- , this.uploadParts(uploadId, parts.slice(start, start + this.queueSize))];
49608
-
49609
- case 6:
49610
49601
  // Upload as many as `queueSize` parts simultaneously
49611
- _b.sent();
49612
- /** Call cleanup a second time in case there were part upload requests
49613
- * in flight. This is to ensure that all parts are cleaned up.
49614
- */
49615
-
49616
-
49617
- return [4
49618
- /*yield*/
49619
- , this.checkIfUploadCancelled(uploadId)];
49620
-
49621
- case 7:
49622
- /** Call cleanup a second time in case there were part upload requests
49623
- * in flight. This is to ensure that all parts are cleaned up.
49624
- */
49625
- _b.sent();
49602
+ _c.sent();
49626
49603
 
49627
- _b.label = 8;
49604
+ _c.label = 6;
49628
49605
 
49629
- case 8:
49606
+ case 6:
49630
49607
  start += this.queueSize;
49631
49608
  return [3
49632
49609
  /*break*/
49633
49610
  , 4];
49634
49611
 
49635
- case 9:
49612
+ case 7:
49636
49613
  parts.map(function (part) {
49637
49614
  _this.removeEventListener(part);
49638
49615
  });
49639
49616
  return [4
49640
49617
  /*yield*/
49641
- , this.finishMultiPartUpload(uploadId)];
49618
+ , this.finishMultiPartUpload(this.uploadId)];
49642
49619
 
49643
- case 10:
49620
+ case 8:
49644
49621
  // Step 3: Finalize the upload such that S3 can recreate the file
49645
49622
  return [2
49646
49623
  /*return*/
49647
- , _b.sent()];
49624
+ , _c.sent()];
49625
+
49626
+ case 9:
49627
+ return [3
49628
+ /*break*/
49629
+ , 12];
49630
+
49631
+ case 10:
49632
+ error_1 = _c.sent(); // if any error is thrown, call cleanup
49633
+
49634
+ return [4
49635
+ /*yield*/
49636
+ , this.cleanup(this.uploadId)];
49637
+
49638
+ case 11:
49639
+ // if any error is thrown, call cleanup
49640
+ _c.sent();
49641
+
49642
+ logger.error('Error. Cancelling the multipart upload.');
49643
+ throw error_1;
49644
+
49645
+ case 12:
49646
+ return [2
49647
+ /*return*/
49648
+ ];
49648
49649
  }
49649
49650
  });
49650
49651
  });
49651
49652
  };
49652
49653
 
49653
49654
  AWSS3ProviderManagedUpload.prototype.createParts = function () {
49654
- var parts = [];
49655
+ try {
49656
+ var parts = [];
49657
+
49658
+ for (var bodyStart = 0; bodyStart < this.totalBytesToUpload;) {
49659
+ var bodyEnd = Math.min(bodyStart + this.minPartSize, this.totalBytesToUpload);
49660
+ parts.push({
49661
+ bodyPart: this.body.slice(bodyStart, bodyEnd),
49662
+ partNumber: parts.length + 1,
49663
+ emitter: new events__WEBPACK_IMPORTED_MODULE_3__["EventEmitter"](),
49664
+ _lastUploadedBytes: 0
49665
+ });
49666
+ bodyStart += this.minPartSize;
49667
+ }
49655
49668
 
49656
- for (var bodyStart = 0; bodyStart < this.totalBytesToUpload;) {
49657
- var bodyEnd = Math.min(bodyStart + this.minPartSize, this.totalBytesToUpload);
49658
- parts.push({
49659
- bodyPart: this.body.slice(bodyStart, bodyEnd),
49660
- partNumber: parts.length + 1,
49661
- emitter: new events__WEBPACK_IMPORTED_MODULE_3__["EventEmitter"](),
49662
- _lastUploadedBytes: 0
49663
- });
49664
- bodyStart += this.minPartSize;
49669
+ return parts;
49670
+ } catch (error) {
49671
+ logger.error(error);
49672
+ throw error;
49665
49673
  }
49666
-
49667
- return parts;
49668
49674
  };
49669
49675
 
49670
49676
  AWSS3ProviderManagedUpload.prototype.createMultiPartUpload = function () {
49671
49677
  return __awaiter(this, void 0, void 0, function () {
49672
- var createMultiPartUploadCommand, response;
49678
+ var createMultiPartUploadCommand, response, error_2;
49673
49679
  return __generator(this, function (_a) {
49674
49680
  switch (_a.label) {
49675
49681
  case 0:
49682
+ _a.trys.push([0, 2,, 3]);
49683
+
49676
49684
  createMultiPartUploadCommand = new _aws_sdk_client_s3__WEBPACK_IMPORTED_MODULE_1__["CreateMultipartUploadCommand"](this.params);
49677
49685
  return [4
49678
49686
  /*yield*/
@@ -49684,6 +49692,16 @@ function () {
49684
49692
  return [2
49685
49693
  /*return*/
49686
49694
  , response.UploadId];
49695
+
49696
+ case 2:
49697
+ error_2 = _a.sent();
49698
+ logger.error(error_2);
49699
+ throw error_2;
49700
+
49701
+ case 3:
49702
+ return [2
49703
+ /*return*/
49704
+ ];
49687
49705
  }
49688
49706
  });
49689
49707
  });
@@ -49696,7 +49714,7 @@ function () {
49696
49714
 
49697
49715
  AWSS3ProviderManagedUpload.prototype.uploadParts = function (uploadId, parts) {
49698
49716
  return __awaiter(this, void 0, void 0, function () {
49699
- var allResults, i, error_1;
49717
+ var allResults, i, error_3;
49700
49718
 
49701
49719
  var _this = this;
49702
49720
 
@@ -49760,12 +49778,9 @@ function () {
49760
49778
  , 3];
49761
49779
 
49762
49780
  case 2:
49763
- error_1 = _a.sent();
49764
- logger.error('error happened while uploading a part. Cancelling the multipart upload', error_1);
49765
- this.cancelUpload();
49766
- return [2
49767
- /*return*/
49768
- ];
49781
+ error_3 = _a.sent();
49782
+ logger.error('Error happened while uploading a part. Cancelling the multipart upload');
49783
+ throw error_3;
49769
49784
 
49770
49785
  case 3:
49771
49786
  return [2
@@ -49778,7 +49793,7 @@ function () {
49778
49793
 
49779
49794
  AWSS3ProviderManagedUpload.prototype.finishMultiPartUpload = function (uploadId) {
49780
49795
  return __awaiter(this, void 0, void 0, function () {
49781
- var input, completeUploadCommand, data, error_2;
49796
+ var input, completeUploadCommand, data, error_4;
49782
49797
  return __generator(this, function (_a) {
49783
49798
  switch (_a.label) {
49784
49799
  case 0:
@@ -49807,59 +49822,11 @@ function () {
49807
49822
  , data.Key];
49808
49823
 
49809
49824
  case 3:
49810
- error_2 = _a.sent();
49811
- logger.error('error happened while finishing the upload. Cancelling the multipart upload', error_2);
49812
- this.cancelUpload();
49813
- return [2
49814
- /*return*/
49815
- ];
49816
-
49817
- case 4:
49818
- return [2
49819
- /*return*/
49820
- ];
49821
- }
49822
- });
49823
- });
49824
- };
49825
-
49826
- AWSS3ProviderManagedUpload.prototype.checkIfUploadCancelled = function (uploadId) {
49827
- return __awaiter(this, void 0, void 0, function () {
49828
- var errorMessage, error_3;
49829
- return __generator(this, function (_a) {
49830
- switch (_a.label) {
49831
- case 0:
49832
- if (!this.cancel) return [3
49833
- /*break*/
49834
- , 5];
49835
- errorMessage = 'Upload was cancelled.';
49836
- _a.label = 1;
49837
-
49838
- case 1:
49839
- _a.trys.push([1, 3,, 4]);
49840
-
49841
- return [4
49842
- /*yield*/
49843
- , this.cleanup(uploadId)];
49844
-
49845
- case 2:
49846
- _a.sent();
49847
-
49848
- return [3
49849
- /*break*/
49850
- , 4];
49851
-
49852
- case 3:
49853
- error_3 = _a.sent();
49854
- errorMessage += " " + error_3.message;
49855
- return [3
49856
- /*break*/
49857
- , 4];
49825
+ error_4 = _a.sent();
49826
+ logger.error('Error happened while finishing the upload.');
49827
+ throw error_4;
49858
49828
 
49859
49829
  case 4:
49860
- throw new Error(errorMessage);
49861
-
49862
- case 5:
49863
49830
  return [2
49864
49831
  /*return*/
49865
49832
  ];
@@ -49868,10 +49835,6 @@ function () {
49868
49835
  });
49869
49836
  };
49870
49837
 
49871
- AWSS3ProviderManagedUpload.prototype.cancelUpload = function () {
49872
- this.cancel = true;
49873
- };
49874
-
49875
49838
  AWSS3ProviderManagedUpload.prototype.cleanup = function (uploadId) {
49876
49839
  return __awaiter(this, void 0, void 0, function () {
49877
49840
  var input, data;
@@ -49903,7 +49866,7 @@ function () {
49903
49866
  data = _a.sent();
49904
49867
 
49905
49868
  if (data && data.Parts && data.Parts.length > 0) {
49906
- throw new Error('Multi Part upload clean up failed');
49869
+ throw new Error('Multipart upload clean up failed.');
49907
49870
  }
49908
49871
 
49909
49872
  return [2