@aws-amplify/storage 5.6.4-api-v6.2 → 5.6.4-api-v6.13
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.
- package/lib/AwsClients/S3/abortMultipartUpload.d.ts +21 -0
- package/lib/AwsClients/S3/abortMultipartUpload.js +85 -0
- package/lib/AwsClients/S3/base.d.ts +54 -0
- package/lib/AwsClients/S3/base.js +75 -0
- package/lib/AwsClients/S3/completeMultipartUpload.d.ts +20 -0
- package/lib/AwsClients/S3/completeMultipartUpload.js +162 -0
- package/lib/AwsClients/S3/copyObject.d.ts +24 -0
- package/lib/AwsClients/S3/copyObject.js +98 -0
- package/lib/AwsClients/S3/createMultipartUpload.d.ts +21 -0
- package/lib/AwsClients/S3/createMultipartUpload.js +95 -0
- package/lib/AwsClients/S3/deleteObject.d.ts +20 -0
- package/lib/AwsClients/S3/deleteObject.js +86 -0
- package/lib/AwsClients/S3/getObject.d.ts +27 -0
- package/lib/AwsClients/S3/getObject.js +216 -0
- package/lib/AwsClients/S3/headObject.d.ts +20 -0
- package/lib/AwsClients/S3/headObject.js +96 -0
- package/lib/AwsClients/S3/index.d.ts +13 -0
- package/lib/AwsClients/S3/index.js +30 -0
- package/lib/AwsClients/S3/index.native.d.ts +14 -0
- package/lib/AwsClients/S3/index.native.js +31 -0
- package/lib/AwsClients/S3/listObjectsV2.d.ts +20 -0
- package/lib/AwsClients/S3/listObjectsV2.js +146 -0
- package/lib/AwsClients/S3/listParts.d.ts +20 -0
- package/lib/AwsClients/S3/listParts.js +110 -0
- package/lib/AwsClients/S3/putObject.d.ts +23 -0
- package/lib/AwsClients/S3/putObject.js +93 -0
- package/lib/AwsClients/S3/runtime/base64/index.browser.d.ts +2 -0
- package/lib/AwsClients/S3/runtime/base64/index.browser.js +20 -0
- package/lib/AwsClients/S3/runtime/base64/index.native.d.ts +2 -0
- package/lib/AwsClients/S3/runtime/base64/index.native.js +17 -0
- package/lib/AwsClients/S3/runtime/constants.d.ts +9 -0
- package/lib/AwsClients/S3/runtime/constants.js +14 -0
- package/lib/AwsClients/S3/runtime/contentSha256middleware.d.ts +9 -0
- package/lib/AwsClients/S3/runtime/contentSha256middleware.js +70 -0
- package/lib/AwsClients/S3/runtime/index.browser.d.ts +5 -0
- package/lib/AwsClients/S3/runtime/index.browser.js +20 -0
- package/lib/AwsClients/S3/runtime/index.d.ts +5 -0
- package/lib/AwsClients/S3/runtime/index.js +21 -0
- package/lib/AwsClients/S3/runtime/index.native.d.ts +5 -0
- package/lib/AwsClients/S3/runtime/index.native.js +20 -0
- package/lib/AwsClients/S3/runtime/s3TransferHandler/fetch.d.ts +8 -0
- package/lib/AwsClients/S3/runtime/s3TransferHandler/fetch.js +15 -0
- package/lib/AwsClients/S3/runtime/s3TransferHandler/xhr.d.ts +8 -0
- package/lib/AwsClients/S3/runtime/s3TransferHandler/xhr.js +21 -0
- package/lib/AwsClients/S3/runtime/xhrTransferHandler.d.ts +22 -0
- package/lib/AwsClients/S3/runtime/xhrTransferHandler.js +201 -0
- package/lib/AwsClients/S3/runtime/xmlParser/dom.d.ts +8 -0
- package/lib/AwsClients/S3/runtime/xmlParser/dom.js +92 -0
- package/lib/AwsClients/S3/runtime/xmlParser/pureJs.d.ts +10 -0
- package/lib/AwsClients/S3/runtime/xmlParser/pureJs.js +57 -0
- package/lib/AwsClients/S3/types.d.ts +2857 -0
- package/lib/AwsClients/S3/types.js +4 -0
- package/lib/AwsClients/S3/uploadPart.d.ts +20 -0
- package/lib/AwsClients/S3/uploadPart.js +96 -0
- package/lib/AwsClients/S3/utils/deserializeHelpers.d.ts +78 -0
- package/lib/AwsClients/S3/utils/deserializeHelpers.js +153 -0
- package/lib/AwsClients/S3/utils/index.d.ts +5 -0
- package/lib/AwsClients/S3/utils/index.js +30 -0
- package/lib/AwsClients/S3/utils/parsePayload.d.ts +3 -0
- package/lib/AwsClients/S3/utils/parsePayload.js +96 -0
- package/lib/AwsClients/S3/utils/serializeHelpers.d.ts +42 -0
- package/lib/AwsClients/S3/utils/serializeHelpers.js +183 -0
- package/lib/Storage.d.ts +5 -5
- package/lib/Storage.js +60 -31
- package/lib/common/S3ClientUtils.d.ts +24 -15
- package/lib/common/S3ClientUtils.js +83 -95
- package/lib/common/StorageConstants.d.ts +0 -1
- package/lib/common/StorageConstants.js +3 -2
- package/lib/common/StorageErrorStrings.js +3 -1
- package/lib/common/StorageUtils.js +12 -6
- package/lib/index.js +19 -4
- package/lib/providers/AWSS3Provider.d.ts +4 -8
- package/lib/providers/AWSS3Provider.js +210 -139
- package/lib/providers/AWSS3ProviderManagedUpload.d.ts +7 -7
- package/lib/providers/AWSS3ProviderManagedUpload.js +184 -98
- package/lib/providers/AWSS3UploadTask.d.ts +8 -8
- package/lib/providers/AWSS3UploadTask.js +226 -129
- package/lib/providers/index.js +4 -2
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/AWSS3Provider.d.ts +62 -62
- package/lib/types/AWSS3Provider.js +0 -1
- package/lib/types/Provider.d.ts +1 -1
- package/lib/types/Provider.js +0 -1
- package/lib/types/Storage.d.ts +23 -23
- package/lib/types/Storage.js +0 -1
- package/lib/types/index.js +17 -1
- package/lib-esm/AwsClients/S3/abortMultipartUpload.d.ts +21 -0
- package/lib-esm/AwsClients/S3/abortMultipartUpload.js +82 -0
- package/lib-esm/AwsClients/S3/base.d.ts +54 -0
- package/lib-esm/AwsClients/S3/base.js +71 -0
- package/lib-esm/AwsClients/S3/completeMultipartUpload.d.ts +20 -0
- package/lib-esm/AwsClients/S3/completeMultipartUpload.js +159 -0
- package/lib-esm/AwsClients/S3/copyObject.d.ts +24 -0
- package/lib-esm/AwsClients/S3/copyObject.js +95 -0
- package/lib-esm/AwsClients/S3/createMultipartUpload.d.ts +21 -0
- package/lib-esm/AwsClients/S3/createMultipartUpload.js +92 -0
- package/lib-esm/AwsClients/S3/deleteObject.d.ts +20 -0
- package/lib-esm/AwsClients/S3/deleteObject.js +83 -0
- package/lib-esm/AwsClients/S3/getObject.d.ts +27 -0
- package/lib-esm/AwsClients/S3/getObject.js +212 -0
- package/lib-esm/AwsClients/S3/headObject.d.ts +20 -0
- package/lib-esm/AwsClients/S3/headObject.js +93 -0
- package/lib-esm/AwsClients/S3/index.d.ts +13 -0
- package/lib-esm/AwsClients/S3/index.js +14 -0
- package/lib-esm/AwsClients/S3/index.native.d.ts +14 -0
- package/lib-esm/AwsClients/S3/index.native.js +15 -0
- package/lib-esm/AwsClients/S3/listObjectsV2.d.ts +20 -0
- package/lib-esm/AwsClients/S3/listObjectsV2.js +143 -0
- package/lib-esm/AwsClients/S3/listParts.d.ts +20 -0
- package/lib-esm/AwsClients/S3/listParts.js +107 -0
- package/lib-esm/AwsClients/S3/putObject.d.ts +23 -0
- package/lib-esm/AwsClients/S3/putObject.js +90 -0
- package/lib-esm/AwsClients/S3/runtime/base64/index.browser.d.ts +2 -0
- package/lib-esm/AwsClients/S3/runtime/base64/index.browser.js +15 -0
- package/lib-esm/AwsClients/S3/runtime/base64/index.native.d.ts +2 -0
- package/lib-esm/AwsClients/S3/runtime/base64/index.native.js +12 -0
- package/lib-esm/AwsClients/S3/runtime/constants.d.ts +9 -0
- package/lib-esm/AwsClients/S3/runtime/constants.js +11 -0
- package/lib-esm/AwsClients/S3/runtime/contentSha256middleware.d.ts +9 -0
- package/lib-esm/AwsClients/S3/runtime/contentSha256middleware.js +66 -0
- package/lib-esm/AwsClients/S3/runtime/index.browser.d.ts +5 -0
- package/lib-esm/AwsClients/S3/runtime/index.browser.js +8 -0
- package/lib-esm/AwsClients/S3/runtime/index.d.ts +5 -0
- package/lib-esm/AwsClients/S3/runtime/index.js +9 -0
- package/lib-esm/AwsClients/S3/runtime/index.native.d.ts +5 -0
- package/lib-esm/AwsClients/S3/runtime/index.native.js +8 -0
- package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/fetch.d.ts +8 -0
- package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/fetch.js +12 -0
- package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/xhr.d.ts +8 -0
- package/lib-esm/AwsClients/S3/runtime/s3TransferHandler/xhr.js +18 -0
- package/lib-esm/AwsClients/S3/runtime/xhrTransferHandler.d.ts +22 -0
- package/lib-esm/AwsClients/S3/runtime/xhrTransferHandler.js +196 -0
- package/lib-esm/AwsClients/S3/runtime/xmlParser/dom.d.ts +8 -0
- package/lib-esm/AwsClients/S3/runtime/xmlParser/dom.js +89 -0
- package/lib-esm/AwsClients/S3/runtime/xmlParser/pureJs.d.ts +10 -0
- package/lib-esm/AwsClients/S3/runtime/xmlParser/pureJs.js +54 -0
- package/lib-esm/AwsClients/S3/types.d.ts +2857 -0
- package/lib-esm/AwsClients/S3/types.js +3 -0
- package/lib-esm/AwsClients/S3/uploadPart.d.ts +20 -0
- package/lib-esm/AwsClients/S3/uploadPart.js +93 -0
- package/lib-esm/AwsClients/S3/utils/deserializeHelpers.d.ts +78 -0
- package/lib-esm/AwsClients/S3/utils/deserializeHelpers.js +144 -0
- package/lib-esm/AwsClients/S3/utils/index.d.ts +5 -0
- package/lib-esm/AwsClients/S3/utils/index.js +7 -0
- package/lib-esm/AwsClients/S3/utils/parsePayload.d.ts +3 -0
- package/lib-esm/AwsClients/S3/utils/parsePayload.js +91 -0
- package/lib-esm/AwsClients/S3/utils/serializeHelpers.d.ts +42 -0
- package/lib-esm/AwsClients/S3/utils/serializeHelpers.js +176 -0
- package/lib-esm/Storage.d.ts +5 -5
- package/lib-esm/Storage.js +53 -25
- package/lib-esm/common/S3ClientUtils.d.ts +24 -15
- package/lib-esm/common/S3ClientUtils.js +76 -93
- package/lib-esm/common/StorageConstants.d.ts +0 -1
- package/lib-esm/common/StorageConstants.js +2 -2
- package/lib-esm/common/StorageErrorStrings.js +2 -1
- package/lib-esm/common/StorageUtils.js +2 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/providers/AWSS3Provider.d.ts +4 -8
- package/lib-esm/providers/AWSS3Provider.js +162 -115
- package/lib-esm/providers/AWSS3ProviderManagedUpload.d.ts +7 -7
- package/lib-esm/providers/AWSS3ProviderManagedUpload.js +172 -87
- package/lib-esm/providers/AWSS3UploadTask.d.ts +8 -8
- package/lib-esm/providers/AWSS3UploadTask.js +202 -106
- package/lib-esm/providers/index.js +2 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/AWSS3Provider.d.ts +62 -62
- package/lib-esm/types/AWSS3Provider.js +1 -1
- package/lib-esm/types/Provider.d.ts +1 -1
- package/lib-esm/types/Provider.js +1 -1
- package/lib-esm/types/Storage.d.ts +23 -23
- package/lib-esm/types/Storage.js +1 -1
- package/lib-esm/types/index.js +3 -1
- package/package.json +21 -26
- package/src/AwsClients/S3/abortMultipartUpload.ts +62 -0
- package/src/AwsClients/S3/base.ts +109 -0
- package/src/AwsClients/S3/completeMultipartUpload.ts +154 -0
- package/src/AwsClients/S3/copyObject.ts +90 -0
- package/src/AwsClients/S3/createMultipartUpload.ts +75 -0
- package/src/AwsClients/S3/deleteObject.ts +69 -0
- package/src/AwsClients/S3/getObject.ts +173 -0
- package/src/AwsClients/S3/headObject.ts +91 -0
- package/src/AwsClients/S3/index.native.ts +42 -0
- package/src/AwsClients/S3/index.ts +41 -0
- package/src/AwsClients/S3/listObjectsV2.ts +130 -0
- package/src/AwsClients/S3/listParts.ts +97 -0
- package/src/AwsClients/S3/putObject.ts +94 -0
- package/src/AwsClients/S3/runtime/base64/index.browser.ts +21 -0
- package/src/AwsClients/S3/runtime/base64/index.native.ts +16 -0
- package/src/AwsClients/S3/runtime/constants.ts +16 -0
- package/src/AwsClients/S3/runtime/contentSha256middleware.ts +29 -0
- package/src/AwsClients/S3/runtime/index.browser.ts +14 -0
- package/src/AwsClients/S3/runtime/index.native.ts +14 -0
- package/src/AwsClients/S3/runtime/index.ts +15 -0
- package/src/AwsClients/S3/runtime/s3TransferHandler/fetch.ts +23 -0
- package/src/AwsClients/S3/runtime/s3TransferHandler/xhr.ts +35 -0
- package/src/AwsClients/S3/runtime/xhrTransferHandler.ts +254 -0
- package/src/AwsClients/S3/runtime/xmlParser/dom.ts +92 -0
- package/src/AwsClients/S3/runtime/xmlParser/pureJs.ts +55 -0
- package/src/AwsClients/S3/types.ts +2877 -0
- package/src/AwsClients/S3/uploadPart.ts +83 -0
- package/src/AwsClients/S3/utils/deserializeHelpers.ts +136 -0
- package/src/AwsClients/S3/utils/index.ts +27 -0
- package/src/AwsClients/S3/utils/parsePayload.ts +45 -0
- package/src/AwsClients/S3/utils/serializeHelpers.ts +112 -0
- package/src/Storage.ts +30 -27
- package/src/common/S3ClientUtils.ts +57 -113
- package/src/common/StorageConstants.ts +2 -2
- package/src/common/StorageErrorStrings.ts +2 -0
- package/src/common/StorageUtils.ts +2 -0
- package/src/providers/AWSS3Provider.ts +80 -100
- package/src/providers/AWSS3ProviderManagedUpload.ts +56 -63
- package/src/providers/AWSS3UploadTask.ts +86 -87
- package/src/providers/index.ts +2 -0
- package/src/types/AWSS3Provider.ts +55 -49
- package/lib/.tsbuildinfo +0 -3
- package/lib/Storage.js.map +0 -1
- package/lib/common/S3ClientUtils.js.map +0 -1
- package/lib/common/StorageConstants.js.map +0 -1
- package/lib/common/StorageErrorStrings.js.map +0 -1
- package/lib/common/StorageUtils.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/providers/AWSS3Provider.js.map +0 -1
- package/lib/providers/AWSS3ProviderManagedUpload.js.map +0 -1
- package/lib/providers/AWSS3UploadTask.js.map +0 -1
- package/lib/providers/axios-http-handler.d.ts +0 -40
- package/lib/providers/axios-http-handler.js +0 -193
- package/lib/providers/axios-http-handler.js.map +0 -1
- package/lib/providers/index.js.map +0 -1
- package/lib/types/AWSS3Provider.js.map +0 -1
- package/lib/types/Provider.js.map +0 -1
- package/lib/types/Storage.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/Storage.js.map +0 -1
- package/lib-esm/common/S3ClientUtils.js.map +0 -1
- package/lib-esm/common/StorageConstants.js.map +0 -1
- package/lib-esm/common/StorageErrorStrings.js.map +0 -1
- package/lib-esm/common/StorageUtils.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/providers/AWSS3Provider.js.map +0 -1
- package/lib-esm/providers/AWSS3ProviderManagedUpload.js.map +0 -1
- package/lib-esm/providers/AWSS3UploadTask.js.map +0 -1
- package/lib-esm/providers/axios-http-handler.d.ts +0 -40
- package/lib-esm/providers/axios-http-handler.js +0 -191
- package/lib-esm/providers/axios-http-handler.js.map +0 -1
- package/lib-esm/providers/index.js.map +0 -1
- package/lib-esm/types/AWSS3Provider.js.map +0 -1
- package/lib-esm/types/Provider.js.map +0 -1
- package/lib-esm/types/Storage.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/src/providers/axios-http-handler.ts +0 -242
|
@@ -3,33 +3,30 @@
|
|
|
3
3
|
|
|
4
4
|
import { ConsoleLogger as Logger, StorageAction } from '@aws-amplify/core';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
UploadPartCommand,
|
|
10
|
-
CompleteMultipartUploadCommand,
|
|
11
|
-
CompleteMultipartUploadCommandInput,
|
|
12
|
-
ListPartsCommand,
|
|
13
|
-
AbortMultipartUploadCommand,
|
|
6
|
+
PutObjectInput,
|
|
7
|
+
putObject,
|
|
8
|
+
createMultipartUpload,
|
|
14
9
|
CompletedPart,
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
uploadPart,
|
|
11
|
+
CompleteMultipartUploadInput,
|
|
12
|
+
completeMultipartUpload,
|
|
13
|
+
abortMultipartUpload,
|
|
14
|
+
listParts,
|
|
15
|
+
} from '../AwsClients/S3';
|
|
17
16
|
import {
|
|
18
|
-
SEND_UPLOAD_PROGRESS_EVENT,
|
|
19
17
|
SEND_DOWNLOAD_PROGRESS_EVENT,
|
|
20
|
-
|
|
21
|
-
} from '
|
|
22
|
-
import
|
|
18
|
+
SEND_UPLOAD_PROGRESS_EVENT,
|
|
19
|
+
} from '../AwsClients/S3/utils';
|
|
20
|
+
import { EventEmitter } from 'events';
|
|
23
21
|
import {
|
|
24
|
-
autoAdjustClockskewMiddleware,
|
|
25
|
-
autoAdjustClockskewMiddlewareOptions,
|
|
26
22
|
calculatePartSize,
|
|
27
|
-
createPrefixMiddleware,
|
|
28
|
-
createS3Client,
|
|
29
|
-
prefixMiddlewareOptions,
|
|
30
23
|
DEFAULT_PART_SIZE,
|
|
31
24
|
DEFAULT_QUEUE_SIZE,
|
|
32
25
|
MAX_OBJECT_SIZE,
|
|
26
|
+
S3ResolvedConfig,
|
|
27
|
+
loadS3Config,
|
|
28
|
+
getPrefix,
|
|
29
|
+
credentialsProvider,
|
|
33
30
|
} from '../common/S3ClientUtils';
|
|
34
31
|
|
|
35
32
|
const logger = new Logger('AWSS3ProviderManagedUpload');
|
|
@@ -37,7 +34,7 @@ const logger = new Logger('AWSS3ProviderManagedUpload');
|
|
|
37
34
|
export declare interface Part {
|
|
38
35
|
bodyPart: any;
|
|
39
36
|
partNumber: number;
|
|
40
|
-
emitter:
|
|
37
|
+
emitter: EventEmitter;
|
|
41
38
|
etag?: string;
|
|
42
39
|
_lastUploadedBytes: number;
|
|
43
40
|
}
|
|
@@ -45,27 +42,27 @@ export declare interface Part {
|
|
|
45
42
|
export class AWSS3ProviderManagedUpload {
|
|
46
43
|
// Data for current upload
|
|
47
44
|
private body;
|
|
48
|
-
private params:
|
|
45
|
+
private params: PutObjectInput;
|
|
49
46
|
private opts = null;
|
|
50
47
|
private completedParts: CompletedPart[] = [];
|
|
51
|
-
private
|
|
48
|
+
private s3Config: S3ResolvedConfig;
|
|
52
49
|
private uploadId: string | undefined;
|
|
53
50
|
private partSize = DEFAULT_PART_SIZE;
|
|
54
51
|
|
|
55
52
|
// Progress reporting
|
|
56
53
|
private bytesUploaded = 0;
|
|
57
54
|
private totalBytesToUpload = 0;
|
|
58
|
-
private emitter:
|
|
55
|
+
private emitter: EventEmitter | null = null;
|
|
59
56
|
|
|
60
|
-
constructor(
|
|
61
|
-
params: PutObjectCommandInput,
|
|
62
|
-
opts,
|
|
63
|
-
emitter: events.EventEmitter
|
|
64
|
-
) {
|
|
57
|
+
constructor(params: PutObjectInput, opts, emitter: EventEmitter) {
|
|
65
58
|
this.params = params;
|
|
66
59
|
this.opts = opts;
|
|
67
60
|
this.emitter = emitter;
|
|
68
|
-
this.
|
|
61
|
+
this.s3Config = loadS3Config({
|
|
62
|
+
...opts,
|
|
63
|
+
emitter,
|
|
64
|
+
storageAction: StorageAction.Put,
|
|
65
|
+
});
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
public async upload() {
|
|
@@ -75,8 +72,10 @@ export class AWSS3ProviderManagedUpload {
|
|
|
75
72
|
if (this.totalBytesToUpload <= DEFAULT_PART_SIZE) {
|
|
76
73
|
// Multipart upload is not required. Upload the sanitized body as is
|
|
77
74
|
this.params.Body = this.body;
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
return putObject(this.s3Config, {
|
|
76
|
+
...this.params,
|
|
77
|
+
Key: await this.getObjectKeyWithPrefix(this.params.Key),
|
|
78
|
+
});
|
|
80
79
|
} else {
|
|
81
80
|
// Step 1: Determine appropriate part size.
|
|
82
81
|
this.partSize = calculatePartSize(this.totalBytesToUpload);
|
|
@@ -127,7 +126,7 @@ export class AWSS3ProviderManagedUpload {
|
|
|
127
126
|
parts.push({
|
|
128
127
|
bodyPart: this.body.slice(bodyStart, bodyEnd),
|
|
129
128
|
partNumber: parts.length + 1,
|
|
130
|
-
emitter: new
|
|
129
|
+
emitter: new EventEmitter(),
|
|
131
130
|
_lastUploadedBytes: 0,
|
|
132
131
|
});
|
|
133
132
|
bodyStart += this.partSize;
|
|
@@ -141,10 +140,10 @@ export class AWSS3ProviderManagedUpload {
|
|
|
141
140
|
|
|
142
141
|
private async createMultiPartUpload() {
|
|
143
142
|
try {
|
|
144
|
-
const
|
|
145
|
-
this.params
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
const response = await createMultipartUpload(this.s3Config, {
|
|
144
|
+
...this.params,
|
|
145
|
+
Key: await this.getObjectKeyWithPrefix(this.params.Key),
|
|
146
|
+
});
|
|
148
147
|
logger.debug(response.UploadId);
|
|
149
148
|
return response.UploadId;
|
|
150
149
|
} catch (error) {
|
|
@@ -162,7 +161,6 @@ export class AWSS3ProviderManagedUpload {
|
|
|
162
161
|
const allResults = await Promise.all(
|
|
163
162
|
parts.map(async part => {
|
|
164
163
|
this.setupEventListener(part);
|
|
165
|
-
const options: AxiosHttpHandlerOptions = { emitter: part.emitter };
|
|
166
164
|
const {
|
|
167
165
|
Key,
|
|
168
166
|
Bucket,
|
|
@@ -170,18 +168,18 @@ export class AWSS3ProviderManagedUpload {
|
|
|
170
168
|
SSECustomerKey,
|
|
171
169
|
SSECustomerKeyMD5,
|
|
172
170
|
} = this.params;
|
|
173
|
-
const res = await
|
|
174
|
-
|
|
171
|
+
const res = await uploadPart(
|
|
172
|
+
{ ...this.s3Config, emitter: part.emitter },
|
|
173
|
+
{
|
|
175
174
|
PartNumber: part.partNumber,
|
|
176
175
|
Body: part.bodyPart,
|
|
177
176
|
UploadId: uploadId,
|
|
178
|
-
Key,
|
|
177
|
+
Key: await this.getObjectKeyWithPrefix(this.params.Key),
|
|
179
178
|
Bucket,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
options
|
|
179
|
+
SSECustomerAlgorithm,
|
|
180
|
+
SSECustomerKey,
|
|
181
|
+
SSECustomerKeyMD5,
|
|
182
|
+
}
|
|
185
183
|
);
|
|
186
184
|
return res;
|
|
187
185
|
})
|
|
@@ -202,16 +200,15 @@ export class AWSS3ProviderManagedUpload {
|
|
|
202
200
|
}
|
|
203
201
|
|
|
204
202
|
private async finishMultiPartUpload(uploadId: string) {
|
|
205
|
-
const input:
|
|
203
|
+
const input: CompleteMultipartUploadInput = {
|
|
206
204
|
Bucket: this.params.Bucket,
|
|
207
|
-
Key: this.params.Key,
|
|
205
|
+
Key: await this.getObjectKeyWithPrefix(this.params.Key),
|
|
208
206
|
UploadId: uploadId,
|
|
209
207
|
MultipartUpload: { Parts: this.completedParts },
|
|
210
208
|
};
|
|
211
|
-
const completeUploadCommand = new CompleteMultipartUploadCommand(input);
|
|
212
209
|
try {
|
|
213
|
-
const
|
|
214
|
-
return
|
|
210
|
+
const { Key } = await completeMultipartUpload(this.s3Config, input);
|
|
211
|
+
return Key;
|
|
215
212
|
} catch (error) {
|
|
216
213
|
logger.error('Error happened while finishing the upload.');
|
|
217
214
|
throw error;
|
|
@@ -232,14 +229,14 @@ export class AWSS3ProviderManagedUpload {
|
|
|
232
229
|
|
|
233
230
|
const input = {
|
|
234
231
|
Bucket: this.params.Bucket,
|
|
235
|
-
Key: this.params.Key,
|
|
232
|
+
Key: await this.getObjectKeyWithPrefix(this.params.Key),
|
|
236
233
|
UploadId: uploadId,
|
|
237
234
|
};
|
|
238
235
|
|
|
239
|
-
await this.
|
|
236
|
+
await abortMultipartUpload(this.s3Config, input);
|
|
240
237
|
|
|
241
238
|
// verify that all parts are removed.
|
|
242
|
-
const data = await this.
|
|
239
|
+
const data = await listParts(this.s3Config, input);
|
|
243
240
|
|
|
244
241
|
if (data && data.Parts && data.Parts.length > 0) {
|
|
245
242
|
throw new Error('Multipart upload clean up failed.');
|
|
@@ -320,16 +317,12 @@ export class AWSS3ProviderManagedUpload {
|
|
|
320
317
|
return false;
|
|
321
318
|
}
|
|
322
319
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
s3client.middlewareStack.add(
|
|
330
|
-
autoAdjustClockskewMiddleware(s3client.config),
|
|
331
|
-
autoAdjustClockskewMiddlewareOptions
|
|
320
|
+
private async getObjectKeyWithPrefix(keyWithoutPrefix: string) {
|
|
321
|
+
return (
|
|
322
|
+
(await getPrefix({
|
|
323
|
+
...this.opts,
|
|
324
|
+
credentials: await credentialsProvider(),
|
|
325
|
+
})) + keyWithoutPrefix
|
|
332
326
|
);
|
|
333
|
-
return s3client;
|
|
334
327
|
}
|
|
335
328
|
}
|
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
CompletedPart,
|
|
4
|
-
S3Client,
|
|
5
|
-
UploadPartCommand,
|
|
6
|
-
CompleteMultipartUploadCommand,
|
|
7
|
-
Part,
|
|
8
|
-
AbortMultipartUploadCommand,
|
|
9
|
-
ListPartsCommand,
|
|
10
|
-
CreateMultipartUploadCommand,
|
|
11
|
-
PutObjectCommandInput,
|
|
12
|
-
ListObjectsV2Command,
|
|
13
|
-
} from '@aws-sdk/client-s3';
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
3
|
import * as events from 'events';
|
|
15
|
-
import axios, { Canceler, CancelTokenSource } from 'axios';
|
|
16
|
-
import { HttpHandlerOptions } from '@aws-sdk/types';
|
|
17
4
|
import { Logger } from '@aws-amplify/core';
|
|
18
5
|
import { UploadTask } from '../types/Provider';
|
|
6
|
+
import {
|
|
7
|
+
PutObjectInput,
|
|
8
|
+
createMultipartUpload,
|
|
9
|
+
uploadPart,
|
|
10
|
+
UploadPartInput,
|
|
11
|
+
listObjectsV2,
|
|
12
|
+
CompletedPart,
|
|
13
|
+
Part,
|
|
14
|
+
listParts,
|
|
15
|
+
completeMultipartUpload,
|
|
16
|
+
abortMultipartUpload,
|
|
17
|
+
} from '../AwsClients/S3';
|
|
18
|
+
import { isCancelError, CANCELED_ERROR_MESSAGE } from '../AwsClients/S3/utils';
|
|
19
19
|
import {
|
|
20
20
|
calculatePartSize,
|
|
21
21
|
DEFAULT_PART_SIZE,
|
|
22
22
|
DEFAULT_QUEUE_SIZE,
|
|
23
23
|
MAX_OBJECT_SIZE,
|
|
24
|
+
S3ResolvedConfig,
|
|
24
25
|
} from '../common/S3ClientUtils';
|
|
25
26
|
import { byteLength, isFile } from '../common/StorageUtils';
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
SET_CONTENT_LENGTH_HEADER,
|
|
29
|
-
UPLOADS_STORAGE_KEY,
|
|
30
|
-
} from '../common/StorageConstants';
|
|
27
|
+
import { UPLOADS_STORAGE_KEY } from '../common/StorageConstants';
|
|
31
28
|
import { StorageAccessLevel } from '..';
|
|
32
29
|
|
|
33
30
|
const logger = new Logger('AWSS3UploadTask');
|
|
@@ -47,19 +44,19 @@ export enum TaskEvents {
|
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
export interface AWSS3UploadTaskParams {
|
|
50
|
-
|
|
47
|
+
s3Config: S3ResolvedConfig;
|
|
51
48
|
file: Blob;
|
|
52
49
|
storage: Storage;
|
|
53
50
|
level: StorageAccessLevel;
|
|
54
|
-
params:
|
|
51
|
+
params: PutObjectInput;
|
|
55
52
|
prefixPromise: Promise<string>;
|
|
56
53
|
emitter?: events.EventEmitter;
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
export interface InProgressRequest {
|
|
60
|
-
uploadPartInput:
|
|
57
|
+
uploadPartInput: UploadPartInput;
|
|
61
58
|
s3Request: Promise<any>;
|
|
62
|
-
|
|
59
|
+
abortController: AbortController;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
export interface UploadTaskCompleteEvent {
|
|
@@ -94,16 +91,16 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
94
91
|
private readonly emitter: events.EventEmitter;
|
|
95
92
|
private readonly file: Blob;
|
|
96
93
|
private readonly queueSize = DEFAULT_QUEUE_SIZE;
|
|
97
|
-
private readonly
|
|
94
|
+
private readonly s3Config: S3ResolvedConfig;
|
|
98
95
|
private readonly storage: Storage;
|
|
99
96
|
private readonly storageSync: Promise<any>;
|
|
100
97
|
private readonly fileId: string;
|
|
101
|
-
private readonly params:
|
|
98
|
+
private readonly params: PutObjectInput;
|
|
102
99
|
private readonly prefixPromise: Promise<string>;
|
|
103
100
|
private partSize: number = DEFAULT_PART_SIZE;
|
|
104
101
|
private inProgress: InProgressRequest[] = [];
|
|
105
102
|
private completedParts: CompletedPart[] = [];
|
|
106
|
-
private queued:
|
|
103
|
+
private queued: UploadPartInput[] = [];
|
|
107
104
|
private bytesUploaded: number = 0;
|
|
108
105
|
private totalBytes: number = 0;
|
|
109
106
|
private uploadId: string;
|
|
@@ -111,7 +108,7 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
111
108
|
public state: AWSS3UploadTaskState = AWSS3UploadTaskState.INIT;
|
|
112
109
|
|
|
113
110
|
constructor({
|
|
114
|
-
|
|
111
|
+
s3Config,
|
|
115
112
|
file,
|
|
116
113
|
emitter,
|
|
117
114
|
storage,
|
|
@@ -120,8 +117,7 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
120
117
|
prefixPromise,
|
|
121
118
|
}: AWSS3UploadTaskParams) {
|
|
122
119
|
this.prefixPromise = prefixPromise;
|
|
123
|
-
this.
|
|
124
|
-
this.s3client.middlewareStack.remove(SET_CONTENT_LENGTH_HEADER);
|
|
120
|
+
this.s3Config = s3Config;
|
|
125
121
|
this.storage = storage;
|
|
126
122
|
this.storageSync = Promise.resolve();
|
|
127
123
|
if (typeof this.storage['sync'] === 'function') {
|
|
@@ -155,15 +151,12 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
155
151
|
key: string;
|
|
156
152
|
bucket: string;
|
|
157
153
|
}) {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
);
|
|
164
|
-
const { Contents = [] } = listObjectRes;
|
|
165
|
-
const prefix = await this.prefixPromise;
|
|
166
|
-
const obj = Contents.find(o => o.Key === `${prefix}${key}`);
|
|
154
|
+
const objectKeyPrefix = await this.prefixPromise;
|
|
155
|
+
const { Contents = [] } = await listObjectsV2(this.s3Config, {
|
|
156
|
+
Bucket: bucket,
|
|
157
|
+
Prefix: objectKeyPrefix + key,
|
|
158
|
+
});
|
|
159
|
+
const obj = Contents.find(o => o.Key === `${objectKeyPrefix}${key}`);
|
|
167
160
|
return obj;
|
|
168
161
|
}
|
|
169
162
|
|
|
@@ -207,16 +200,14 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
207
200
|
cachedUploadFileData.lastTouched = Date.now();
|
|
208
201
|
this.storage.setItem(UPLOADS_STORAGE_KEY, JSON.stringify(uploadRequests));
|
|
209
202
|
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
})
|
|
216
|
-
);
|
|
203
|
+
const { Parts = [] } = await listParts(this.s3Config, {
|
|
204
|
+
Bucket: this.params.Bucket,
|
|
205
|
+
Key: (await this.prefixPromise) + this.params.Key,
|
|
206
|
+
UploadId: cachedUploadFileData.uploadId,
|
|
207
|
+
});
|
|
217
208
|
|
|
218
209
|
return {
|
|
219
|
-
parts:
|
|
210
|
+
parts: Parts,
|
|
220
211
|
uploadId: cachedUploadFileData.uploadId,
|
|
221
212
|
};
|
|
222
213
|
}
|
|
@@ -267,7 +258,7 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
267
258
|
}: {
|
|
268
259
|
eTag: string;
|
|
269
260
|
partNumber: number;
|
|
270
|
-
chunk:
|
|
261
|
+
chunk: UploadPartInput['Body'];
|
|
271
262
|
}) {
|
|
272
263
|
this.completedParts.push({
|
|
273
264
|
ETag: eTag,
|
|
@@ -289,17 +280,15 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
289
280
|
|
|
290
281
|
private async _completeUpload() {
|
|
291
282
|
try {
|
|
292
|
-
await this.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
})
|
|
302
|
-
);
|
|
283
|
+
await completeMultipartUpload(this.s3Config, {
|
|
284
|
+
Bucket: this.params.Bucket,
|
|
285
|
+
Key: (await this.prefixPromise) + this.params.Key,
|
|
286
|
+
UploadId: this.uploadId,
|
|
287
|
+
MultipartUpload: {
|
|
288
|
+
// Parts are not always completed in order, we need to manually sort them
|
|
289
|
+
Parts: [...this.completedParts].sort(comparePartNumber),
|
|
290
|
+
},
|
|
291
|
+
});
|
|
303
292
|
await this._verifyFileSize();
|
|
304
293
|
this._emitEvent<UploadTaskCompleteEvent>(TaskEvents.UPLOAD_COMPLETE, {
|
|
305
294
|
key: this.params.Key,
|
|
@@ -313,13 +302,20 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
313
302
|
}
|
|
314
303
|
|
|
315
304
|
private async _makeUploadPartRequest(
|
|
316
|
-
input:
|
|
317
|
-
|
|
305
|
+
input: UploadPartInput,
|
|
306
|
+
abortSignal: AbortSignal
|
|
318
307
|
) {
|
|
319
308
|
try {
|
|
320
|
-
const res = await
|
|
321
|
-
|
|
322
|
-
|
|
309
|
+
const res = await uploadPart(
|
|
310
|
+
{
|
|
311
|
+
...this.s3Config,
|
|
312
|
+
abortSignal,
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
...input,
|
|
316
|
+
Key: (await this.prefixPromise) + this.params.Key,
|
|
317
|
+
}
|
|
318
|
+
);
|
|
323
319
|
await this._onPartUploadCompletion({
|
|
324
320
|
eTag: res.ETag,
|
|
325
321
|
partNumber: input.PartNumber,
|
|
@@ -333,12 +329,9 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
333
329
|
} else {
|
|
334
330
|
logger.error('error starting next part of upload: ', err);
|
|
335
331
|
}
|
|
336
|
-
//
|
|
332
|
+
// xhr transfer handlers' cancel will also throw an error, however we don't need to emit an event in that case as it's an
|
|
337
333
|
// expected behavior
|
|
338
|
-
if (
|
|
339
|
-
!axios.isCancel(err) &&
|
|
340
|
-
err.message !== AWSS3ProviderUploadErrorStrings.UPLOAD_PAUSED_MESSAGE
|
|
341
|
-
) {
|
|
334
|
+
if (!isCancelError(err) && err.message !== CANCELED_ERROR_MESSAGE) {
|
|
342
335
|
this._emitEvent(TaskEvents.ERROR, err);
|
|
343
336
|
this.pause();
|
|
344
337
|
}
|
|
@@ -347,12 +340,15 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
347
340
|
|
|
348
341
|
private _startNextPart() {
|
|
349
342
|
if (this.queued.length > 0 && this.state !== AWSS3UploadTaskState.PAUSED) {
|
|
350
|
-
const
|
|
343
|
+
const abortController = new AbortController();
|
|
351
344
|
const nextPart = this.queued.shift();
|
|
352
345
|
this.inProgress.push({
|
|
353
346
|
uploadPartInput: nextPart,
|
|
354
|
-
s3Request: this._makeUploadPartRequest(
|
|
355
|
-
|
|
347
|
+
s3Request: this._makeUploadPartRequest(
|
|
348
|
+
nextPart,
|
|
349
|
+
abortController.signal
|
|
350
|
+
),
|
|
351
|
+
abortController,
|
|
356
352
|
});
|
|
357
353
|
}
|
|
358
354
|
}
|
|
@@ -395,7 +391,7 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
395
391
|
|
|
396
392
|
private _createParts() {
|
|
397
393
|
const size = this.file.size;
|
|
398
|
-
const parts:
|
|
394
|
+
const parts: UploadPartInput[] = [];
|
|
399
395
|
for (let bodyStart = 0; bodyStart < size; ) {
|
|
400
396
|
const bodyEnd = Math.min(bodyStart + this.partSize, size);
|
|
401
397
|
parts.push({
|
|
@@ -430,9 +426,10 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
430
426
|
}
|
|
431
427
|
|
|
432
428
|
private async _initMultipartUpload() {
|
|
433
|
-
const res = await this.
|
|
434
|
-
|
|
435
|
-
|
|
429
|
+
const res = await createMultipartUpload(this.s3Config, {
|
|
430
|
+
...this.params,
|
|
431
|
+
Key: (await this.prefixPromise) + this.params.Key,
|
|
432
|
+
});
|
|
436
433
|
this._cache({
|
|
437
434
|
uploadId: res.UploadId,
|
|
438
435
|
lastTouched: Date.now(),
|
|
@@ -452,7 +449,11 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
452
449
|
this.uploadId = uploadId;
|
|
453
450
|
this.queued = this._createParts();
|
|
454
451
|
this._initCachedUploadParts(parts);
|
|
455
|
-
this.
|
|
452
|
+
if (this._isDone()) {
|
|
453
|
+
this._completeUpload();
|
|
454
|
+
} else {
|
|
455
|
+
this._startUpload();
|
|
456
|
+
}
|
|
456
457
|
} else {
|
|
457
458
|
if (!this.uploadId) {
|
|
458
459
|
const uploadId = await this._initMultipartUpload();
|
|
@@ -462,7 +463,7 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
462
463
|
}
|
|
463
464
|
}
|
|
464
465
|
} catch (err) {
|
|
465
|
-
if (!
|
|
466
|
+
if (!isCancelError(err)) {
|
|
466
467
|
logger.error('Error initializing the upload task', err);
|
|
467
468
|
this._emitEvent(TaskEvents.ERROR, err);
|
|
468
469
|
}
|
|
@@ -506,13 +507,11 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
506
507
|
this.bytesUploaded = 0;
|
|
507
508
|
this.state = AWSS3UploadTaskState.CANCELLED;
|
|
508
509
|
try {
|
|
509
|
-
await this.
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
})
|
|
515
|
-
);
|
|
510
|
+
await abortMultipartUpload(this.s3Config, {
|
|
511
|
+
Bucket: this.params.Bucket,
|
|
512
|
+
Key: (await this.prefixPromise) + this.params.Key,
|
|
513
|
+
UploadId: this.uploadId,
|
|
514
|
+
});
|
|
516
515
|
await this._removeFromCache();
|
|
517
516
|
return true;
|
|
518
517
|
} catch (err) {
|
|
@@ -534,14 +533,14 @@ export class AWSS3UploadTask implements UploadTask {
|
|
|
534
533
|
logger.warn('This task is already paused');
|
|
535
534
|
}
|
|
536
535
|
this.state = AWSS3UploadTaskState.PAUSED;
|
|
537
|
-
//
|
|
536
|
+
// Abort the part request immediately
|
|
538
537
|
// Add the inProgress parts back to pending
|
|
539
538
|
const removedInProgressReq = this.inProgress.splice(
|
|
540
539
|
0,
|
|
541
540
|
this.inProgress.length
|
|
542
541
|
);
|
|
543
542
|
removedInProgressReq.forEach(req => {
|
|
544
|
-
req.
|
|
543
|
+
req.abortController.abort();
|
|
545
544
|
});
|
|
546
545
|
// Put all removed in progress parts back into the queue
|
|
547
546
|
this.queued.unshift(
|
package/src/providers/index.ts
CHANGED