@aws-amplify/storage 5.6.4-api-v6.2 → 5.6.4-api-v6.23
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 +95 -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 +98 -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 +61 -31
- package/lib/common/MD5utils.d.ts +1 -0
- package/lib/common/MD5utils.js +79 -0
- package/lib/common/MD5utils.native.d.ts +1 -0
- package/lib/common/MD5utils.native.js +83 -0
- 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 +205 -99
- 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 +92 -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 +95 -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 +54 -25
- package/lib-esm/common/MD5utils.d.ts +1 -0
- package/lib-esm/common/MD5utils.js +75 -0
- package/lib-esm/common/MD5utils.native.d.ts +1 -0
- package/lib-esm/common/MD5utils.native.js +79 -0
- 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 +193 -88
- 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 +99 -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 +88 -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 +31 -27
- package/src/common/MD5utils.native.ts +38 -0
- package/src/common/MD5utils.ts +33 -0
- 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 +74 -64
- 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
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Endpoint,
|
|
6
|
+
HttpRequest,
|
|
7
|
+
parseMetadata,
|
|
8
|
+
presignUrl,
|
|
9
|
+
UserAgentOptions,
|
|
10
|
+
PresignUrlOptions,
|
|
11
|
+
EMPTY_SHA256_HASH,
|
|
12
|
+
} from '@aws-amplify/core/internals/aws-client-utils';
|
|
13
|
+
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
14
|
+
import { USER_AGENT_HEADER } from '@aws-amplify/core';
|
|
15
|
+
|
|
16
|
+
import { S3EndpointResolverOptions, defaultConfig } from './base';
|
|
17
|
+
import type {
|
|
18
|
+
CompatibleHttpResponse,
|
|
19
|
+
GetObjectCommandInput,
|
|
20
|
+
GetObjectCommandOutput,
|
|
21
|
+
} from './types';
|
|
22
|
+
import {
|
|
23
|
+
deserializeBoolean,
|
|
24
|
+
deserializeMetadata,
|
|
25
|
+
deserializeNumber,
|
|
26
|
+
deserializeTimestamp,
|
|
27
|
+
map,
|
|
28
|
+
parseXmlError,
|
|
29
|
+
s3TransferHandler,
|
|
30
|
+
serializeObjectSsecOptionsToHeaders,
|
|
31
|
+
serializePathnameObjectKey,
|
|
32
|
+
CONTENT_SHA256_HEADER,
|
|
33
|
+
} from './utils';
|
|
34
|
+
|
|
35
|
+
export type GetObjectInput = Pick<
|
|
36
|
+
GetObjectCommandInput,
|
|
37
|
+
| 'Bucket'
|
|
38
|
+
| 'Key'
|
|
39
|
+
| 'ResponseCacheControl'
|
|
40
|
+
| 'ResponseContentDisposition'
|
|
41
|
+
| 'ResponseContentEncoding'
|
|
42
|
+
| 'ResponseContentLanguage'
|
|
43
|
+
| 'ResponseContentType'
|
|
44
|
+
| 'SSECustomerAlgorithm'
|
|
45
|
+
| 'SSECustomerKey'
|
|
46
|
+
// TODO(AllanZhengYP): remove in V6.
|
|
47
|
+
| 'SSECustomerKeyMD5'
|
|
48
|
+
>;
|
|
49
|
+
|
|
50
|
+
export type GetObjectOutput = GetObjectCommandOutput;
|
|
51
|
+
|
|
52
|
+
const getObjectSerializer = async (
|
|
53
|
+
input: GetObjectInput,
|
|
54
|
+
endpoint: Endpoint
|
|
55
|
+
): Promise<HttpRequest> => {
|
|
56
|
+
const headers = await serializeObjectSsecOptionsToHeaders(input);
|
|
57
|
+
const query = map(input, {
|
|
58
|
+
'response-cache-control': 'ResponseCacheControl',
|
|
59
|
+
'response-content-disposition': 'ResponseContentDisposition',
|
|
60
|
+
'response-content-encoding': 'ResponseContentEncoding',
|
|
61
|
+
'response-content-language': 'ResponseContentLanguage',
|
|
62
|
+
'response-content-type': 'ResponseContentType',
|
|
63
|
+
});
|
|
64
|
+
const url = new URL(endpoint.url.toString());
|
|
65
|
+
url.pathname = serializePathnameObjectKey(url, input.Key);
|
|
66
|
+
url.search = new URLSearchParams(query).toString();
|
|
67
|
+
return {
|
|
68
|
+
method: 'GET',
|
|
69
|
+
headers,
|
|
70
|
+
url,
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const getObjectDeserializer = async (
|
|
75
|
+
response: CompatibleHttpResponse
|
|
76
|
+
): Promise<GetObjectOutput> => {
|
|
77
|
+
if (response.statusCode >= 300) {
|
|
78
|
+
const error = await parseXmlError(response);
|
|
79
|
+
throw error;
|
|
80
|
+
} else if (!response.body) {
|
|
81
|
+
throw new Error('Got empty response body.');
|
|
82
|
+
} else {
|
|
83
|
+
return {
|
|
84
|
+
...map(response.headers, {
|
|
85
|
+
DeleteMarker: ['x-amz-delete-marker', deserializeBoolean],
|
|
86
|
+
AcceptRanges: 'accept-ranges',
|
|
87
|
+
Expiration: 'x-amz-expiration',
|
|
88
|
+
Restore: 'x-amz-restore',
|
|
89
|
+
LastModified: ['last-modified', deserializeTimestamp],
|
|
90
|
+
ContentLength: ['content-length', deserializeNumber],
|
|
91
|
+
ETag: 'etag',
|
|
92
|
+
ChecksumCRC32: 'x-amz-checksum-crc32',
|
|
93
|
+
ChecksumCRC32C: 'x-amz-checksum-crc32c',
|
|
94
|
+
ChecksumSHA1: 'x-amz-checksum-sha1',
|
|
95
|
+
ChecksumSHA256: 'x-amz-checksum-sha256',
|
|
96
|
+
MissingMeta: ['x-amz-missing-meta', deserializeNumber],
|
|
97
|
+
VersionId: 'x-amz-version-id',
|
|
98
|
+
CacheControl: 'cache-control',
|
|
99
|
+
ContentDisposition: 'content-disposition',
|
|
100
|
+
ContentEncoding: 'content-encoding',
|
|
101
|
+
ContentLanguage: 'content-language',
|
|
102
|
+
ContentRange: 'content-range',
|
|
103
|
+
ContentType: 'content-type',
|
|
104
|
+
Expires: ['expires', deserializeTimestamp],
|
|
105
|
+
WebsiteRedirectLocation: 'x-amz-website-redirect-location',
|
|
106
|
+
ServerSideEncryption: 'x-amz-server-side-encryption',
|
|
107
|
+
SSECustomerAlgorithm: 'x-amz-server-side-encryption-customer-algorithm',
|
|
108
|
+
SSECustomerKeyMD5: 'x-amz-server-side-encryption-customer-key-md5',
|
|
109
|
+
SSEKMSKeyId: 'x-amz-server-side-encryption-aws-kms-key-id',
|
|
110
|
+
BucketKeyEnabled: [
|
|
111
|
+
'x-amz-server-side-encryption-bucket-key-enabled',
|
|
112
|
+
deserializeBoolean,
|
|
113
|
+
],
|
|
114
|
+
StorageClass: 'x-amz-storage-class',
|
|
115
|
+
RequestCharged: 'x-amz-request-charged',
|
|
116
|
+
ReplicationStatus: 'x-amz-replication-status',
|
|
117
|
+
PartsCount: ['x-amz-mp-parts-count', deserializeNumber],
|
|
118
|
+
TagCount: ['x-amz-tagging-count', deserializeNumber],
|
|
119
|
+
ObjectLockMode: 'x-amz-object-lock-mode',
|
|
120
|
+
ObjectLockRetainUntilDate: [
|
|
121
|
+
'x-amz-object-lock-retain-until-date',
|
|
122
|
+
deserializeTimestamp,
|
|
123
|
+
],
|
|
124
|
+
ObjectLockLegalHoldStatus: 'x-amz-object-lock-legal-hold',
|
|
125
|
+
}),
|
|
126
|
+
Metadata: deserializeMetadata(response.headers),
|
|
127
|
+
$metadata: parseMetadata(response),
|
|
128
|
+
Body: response.body,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const getObject = composeServiceApi(
|
|
134
|
+
s3TransferHandler,
|
|
135
|
+
getObjectSerializer,
|
|
136
|
+
getObjectDeserializer,
|
|
137
|
+
{ ...defaultConfig, responseType: 'blob' }
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Get a presigned URL for the `getObject` API.
|
|
142
|
+
*
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
export const getPresignedGetObjectUrl = async (
|
|
146
|
+
config: UserAgentOptions & PresignUrlOptions & S3EndpointResolverOptions,
|
|
147
|
+
input: GetObjectInput
|
|
148
|
+
): Promise<string> => {
|
|
149
|
+
const endpoint = defaultConfig.endpointResolver(config, input);
|
|
150
|
+
const { url, headers, method } = await getObjectSerializer(input, endpoint);
|
|
151
|
+
|
|
152
|
+
// TODO: set content sha256 query parameter with value of UNSIGNED-PAYLOAD.
|
|
153
|
+
// It requires changes in presignUrl. Without this change, the generated url still works,
|
|
154
|
+
// but not the same as other tools like AWS SDK and CLI.
|
|
155
|
+
url.searchParams.append(CONTENT_SHA256_HEADER, EMPTY_SHA256_HASH);
|
|
156
|
+
url.searchParams.append(
|
|
157
|
+
config.userAgentHeader ?? USER_AGENT_HEADER,
|
|
158
|
+
config.userAgentValue
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
for (const [headerName, value] of Object.entries(headers).sort(
|
|
162
|
+
([key1], [key2]) => key1.localeCompare(key2)
|
|
163
|
+
)) {
|
|
164
|
+
url.searchParams.append(headerName, value);
|
|
165
|
+
}
|
|
166
|
+
return presignUrl(
|
|
167
|
+
{ method, url, body: null },
|
|
168
|
+
{
|
|
169
|
+
...defaultConfig,
|
|
170
|
+
...config,
|
|
171
|
+
}
|
|
172
|
+
).toString();
|
|
173
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Endpoint,
|
|
6
|
+
HttpRequest,
|
|
7
|
+
parseMetadata,
|
|
8
|
+
} from '@aws-amplify/core/internals/aws-client-utils';
|
|
9
|
+
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
10
|
+
import { defaultConfig } from './base';
|
|
11
|
+
import type {
|
|
12
|
+
CompatibleHttpResponse,
|
|
13
|
+
HeadObjectCommandInput,
|
|
14
|
+
HeadObjectCommandOutput,
|
|
15
|
+
} from './types';
|
|
16
|
+
import {
|
|
17
|
+
deserializeMetadata,
|
|
18
|
+
deserializeNumber,
|
|
19
|
+
deserializeTimestamp,
|
|
20
|
+
map,
|
|
21
|
+
parseXmlError,
|
|
22
|
+
s3TransferHandler,
|
|
23
|
+
serializeObjectSsecOptionsToHeaders,
|
|
24
|
+
serializePathnameObjectKey,
|
|
25
|
+
} from './utils';
|
|
26
|
+
|
|
27
|
+
export type HeadObjectInput = Pick<
|
|
28
|
+
HeadObjectCommandInput,
|
|
29
|
+
| 'Bucket'
|
|
30
|
+
| 'Key'
|
|
31
|
+
| 'SSECustomerKey'
|
|
32
|
+
// TODO(AllanZhengYP): remove in V6.
|
|
33
|
+
| 'SSECustomerKeyMD5'
|
|
34
|
+
| 'SSECustomerAlgorithm'
|
|
35
|
+
>;
|
|
36
|
+
|
|
37
|
+
export type HeadObjectOutput = Pick<
|
|
38
|
+
HeadObjectCommandOutput,
|
|
39
|
+
| '$metadata'
|
|
40
|
+
| 'ContentLength'
|
|
41
|
+
| 'ContentType'
|
|
42
|
+
| 'ETag'
|
|
43
|
+
| 'LastModified'
|
|
44
|
+
| 'Metadata'
|
|
45
|
+
| 'VersionId'
|
|
46
|
+
>;
|
|
47
|
+
|
|
48
|
+
const headObjectSerializer = async (
|
|
49
|
+
input: HeadObjectInput,
|
|
50
|
+
endpoint: Endpoint
|
|
51
|
+
): Promise<HttpRequest> => {
|
|
52
|
+
const headers = await serializeObjectSsecOptionsToHeaders(input);
|
|
53
|
+
const url = new URL(endpoint.url.toString());
|
|
54
|
+
url.pathname = serializePathnameObjectKey(url, input.Key);
|
|
55
|
+
return {
|
|
56
|
+
method: 'HEAD',
|
|
57
|
+
headers,
|
|
58
|
+
url,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const headObjectDeserializer = async (
|
|
63
|
+
response: CompatibleHttpResponse
|
|
64
|
+
): Promise<HeadObjectOutput> => {
|
|
65
|
+
if (response.statusCode >= 300) {
|
|
66
|
+
const error = await parseXmlError(response);
|
|
67
|
+
throw error;
|
|
68
|
+
} else {
|
|
69
|
+
const contents = {
|
|
70
|
+
...map(response.headers, {
|
|
71
|
+
ContentLength: ['content-length', deserializeNumber],
|
|
72
|
+
ContentType: 'content-type',
|
|
73
|
+
ETag: 'etag',
|
|
74
|
+
LastModified: ['last-modified', deserializeTimestamp],
|
|
75
|
+
VersionId: 'x-amz-version-id',
|
|
76
|
+
}),
|
|
77
|
+
Metadata: deserializeMetadata(response.headers),
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
$metadata: parseMetadata(response),
|
|
81
|
+
...contents,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const headObject = composeServiceApi(
|
|
87
|
+
s3TransferHandler,
|
|
88
|
+
headObjectSerializer,
|
|
89
|
+
headObjectDeserializer,
|
|
90
|
+
{ ...defaultConfig, responseType: 'text' }
|
|
91
|
+
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import '@aws-amplify/core/polyfills/URL'; // TODO: [v6] install react-native-url-polyfill separately
|
|
4
|
+
|
|
5
|
+
export { SERVICE_NAME } from './base';
|
|
6
|
+
export {
|
|
7
|
+
getObject,
|
|
8
|
+
GetObjectInput,
|
|
9
|
+
GetObjectOutput,
|
|
10
|
+
getPresignedGetObjectUrl,
|
|
11
|
+
} from './getObject';
|
|
12
|
+
export {
|
|
13
|
+
listObjectsV2,
|
|
14
|
+
ListObjectsV2Input,
|
|
15
|
+
ListObjectsV2Output,
|
|
16
|
+
} from './listObjectsV2';
|
|
17
|
+
export { putObject, PutObjectInput, PutObjectOutput } from './putObject';
|
|
18
|
+
export {
|
|
19
|
+
createMultipartUpload,
|
|
20
|
+
CreateMultipartUploadInput,
|
|
21
|
+
CreateMultipartUploadOutput,
|
|
22
|
+
} from './createMultipartUpload';
|
|
23
|
+
export { uploadPart, UploadPartInput, UploadPartOutput } from './uploadPart';
|
|
24
|
+
export {
|
|
25
|
+
completeMultipartUpload,
|
|
26
|
+
CompleteMultipartUploadInput,
|
|
27
|
+
CompleteMultipartUploadOutput,
|
|
28
|
+
} from './completeMultipartUpload';
|
|
29
|
+
export { listParts, ListPartsInput, ListPartsOutput } from './listParts';
|
|
30
|
+
export {
|
|
31
|
+
abortMultipartUpload,
|
|
32
|
+
AbortMultipartUploadInput,
|
|
33
|
+
AbortMultipartUploadOutput,
|
|
34
|
+
} from './abortMultipartUpload';
|
|
35
|
+
export { copyObject, CopyObjectInput, CopyObjectOutput } from './copyObject';
|
|
36
|
+
export { headObject, HeadObjectInput, HeadObjectOutput } from './headObject';
|
|
37
|
+
export {
|
|
38
|
+
deleteObject,
|
|
39
|
+
DeleteObjectInput,
|
|
40
|
+
DeleteObjectOutput,
|
|
41
|
+
} from './deleteObject';
|
|
42
|
+
export { CompletedPart, Part, _Object } from './types';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export { SERVICE_NAME } from './base';
|
|
5
|
+
export {
|
|
6
|
+
getObject,
|
|
7
|
+
GetObjectInput,
|
|
8
|
+
GetObjectOutput,
|
|
9
|
+
getPresignedGetObjectUrl,
|
|
10
|
+
} from './getObject';
|
|
11
|
+
export {
|
|
12
|
+
listObjectsV2,
|
|
13
|
+
ListObjectsV2Input,
|
|
14
|
+
ListObjectsV2Output,
|
|
15
|
+
} from './listObjectsV2';
|
|
16
|
+
export { putObject, PutObjectInput, PutObjectOutput } from './putObject';
|
|
17
|
+
export {
|
|
18
|
+
createMultipartUpload,
|
|
19
|
+
CreateMultipartUploadInput,
|
|
20
|
+
CreateMultipartUploadOutput,
|
|
21
|
+
} from './createMultipartUpload';
|
|
22
|
+
export { uploadPart, UploadPartInput, UploadPartOutput } from './uploadPart';
|
|
23
|
+
export {
|
|
24
|
+
completeMultipartUpload,
|
|
25
|
+
CompleteMultipartUploadInput,
|
|
26
|
+
CompleteMultipartUploadOutput,
|
|
27
|
+
} from './completeMultipartUpload';
|
|
28
|
+
export { listParts, ListPartsInput, ListPartsOutput } from './listParts';
|
|
29
|
+
export {
|
|
30
|
+
abortMultipartUpload,
|
|
31
|
+
AbortMultipartUploadInput,
|
|
32
|
+
AbortMultipartUploadOutput,
|
|
33
|
+
} from './abortMultipartUpload';
|
|
34
|
+
export { copyObject, CopyObjectInput, CopyObjectOutput } from './copyObject';
|
|
35
|
+
export { headObject, HeadObjectInput, HeadObjectOutput } from './headObject';
|
|
36
|
+
export {
|
|
37
|
+
deleteObject,
|
|
38
|
+
DeleteObjectInput,
|
|
39
|
+
DeleteObjectOutput,
|
|
40
|
+
} from './deleteObject';
|
|
41
|
+
export { CompletedPart, Part, _Object } from './types';
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Endpoint,
|
|
6
|
+
HttpRequest,
|
|
7
|
+
HttpResponse,
|
|
8
|
+
parseMetadata,
|
|
9
|
+
} from '@aws-amplify/core/internals/aws-client-utils';
|
|
10
|
+
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
11
|
+
import type {
|
|
12
|
+
ListObjectsV2CommandInput,
|
|
13
|
+
ListObjectsV2CommandOutput,
|
|
14
|
+
} from './types';
|
|
15
|
+
import { defaultConfig } from './base';
|
|
16
|
+
import {
|
|
17
|
+
assignStringVariables,
|
|
18
|
+
deserializeBoolean,
|
|
19
|
+
deserializeNumber,
|
|
20
|
+
deserializeTimestamp,
|
|
21
|
+
emptyArrayGuard,
|
|
22
|
+
map,
|
|
23
|
+
parseXmlBody,
|
|
24
|
+
parseXmlError,
|
|
25
|
+
s3TransferHandler,
|
|
26
|
+
serializePathnameObjectKey,
|
|
27
|
+
} from './utils';
|
|
28
|
+
|
|
29
|
+
export type ListObjectsV2Input = ListObjectsV2CommandInput;
|
|
30
|
+
|
|
31
|
+
export type ListObjectsV2Output = ListObjectsV2CommandOutput;
|
|
32
|
+
|
|
33
|
+
const listObjectsV2Serializer = (
|
|
34
|
+
input: ListObjectsV2Input,
|
|
35
|
+
endpoint: Endpoint
|
|
36
|
+
): HttpRequest => {
|
|
37
|
+
const headers = assignStringVariables({
|
|
38
|
+
'x-amz-request-payer': input.RequestPayer,
|
|
39
|
+
'x-amz-expected-bucket-owner': input.ExpectedBucketOwner,
|
|
40
|
+
});
|
|
41
|
+
const query = assignStringVariables({
|
|
42
|
+
'list-type': '2',
|
|
43
|
+
'continuation-token': input.ContinuationToken,
|
|
44
|
+
delimiter: input.Delimiter,
|
|
45
|
+
'encoding-type': input.EncodingType,
|
|
46
|
+
'fetch-owner': input.FetchOwner,
|
|
47
|
+
'max-keys': input.MaxKeys,
|
|
48
|
+
prefix: input.Prefix,
|
|
49
|
+
'start-after': input.StartAfter,
|
|
50
|
+
});
|
|
51
|
+
const url = new URL(endpoint.url.toString());
|
|
52
|
+
url.search = new URLSearchParams(query).toString();
|
|
53
|
+
return {
|
|
54
|
+
method: 'GET',
|
|
55
|
+
headers,
|
|
56
|
+
url,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const listObjectsV2Deserializer = async (
|
|
61
|
+
response: HttpResponse
|
|
62
|
+
): Promise<ListObjectsV2Output> => {
|
|
63
|
+
if (response.statusCode >= 300) {
|
|
64
|
+
const error = await parseXmlError(response);
|
|
65
|
+
throw error;
|
|
66
|
+
} else {
|
|
67
|
+
const parsed = await parseXmlBody(response);
|
|
68
|
+
const contents = map(parsed, {
|
|
69
|
+
CommonPrefixes: [
|
|
70
|
+
'CommonPrefixes',
|
|
71
|
+
value => emptyArrayGuard(value, deserializeCommonPrefixList),
|
|
72
|
+
],
|
|
73
|
+
Contents: [
|
|
74
|
+
'Contents',
|
|
75
|
+
value => emptyArrayGuard(value, deserializeObjectList),
|
|
76
|
+
],
|
|
77
|
+
ContinuationToken: 'ContinuationToken',
|
|
78
|
+
Delimiter: 'Delimiter',
|
|
79
|
+
EncodingType: 'EncodingType',
|
|
80
|
+
IsTruncated: ['IsTruncated', deserializeBoolean],
|
|
81
|
+
KeyCount: ['KeyCount', deserializeNumber],
|
|
82
|
+
MaxKeys: ['MaxKeys', deserializeNumber],
|
|
83
|
+
Name: 'Name',
|
|
84
|
+
NextContinuationToken: 'NextContinuationToken',
|
|
85
|
+
Prefix: 'Prefix',
|
|
86
|
+
StartAfter: 'StartAfter',
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
$metadata: parseMetadata(response),
|
|
90
|
+
...contents,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const deserializeCommonPrefixList = (output: any[]) =>
|
|
96
|
+
output.map(deserializeCommonPrefix);
|
|
97
|
+
|
|
98
|
+
const deserializeCommonPrefix = (output: any) =>
|
|
99
|
+
map(output, {
|
|
100
|
+
Prefix: 'Prefix',
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const deserializeObjectList = (output: any[]) => output.map(deserializeObject);
|
|
104
|
+
|
|
105
|
+
const deserializeObject = (output: any) =>
|
|
106
|
+
map(output, {
|
|
107
|
+
Key: 'Key',
|
|
108
|
+
LastModified: ['LastModified', deserializeTimestamp],
|
|
109
|
+
ETag: 'ETag',
|
|
110
|
+
ChecksumAlgorithm: [
|
|
111
|
+
'ChecksumAlgorithm',
|
|
112
|
+
value => emptyArrayGuard(value, deserializeChecksumAlgorithmList),
|
|
113
|
+
],
|
|
114
|
+
Size: ['Size', deserializeNumber],
|
|
115
|
+
StorageClass: 'StorageClass',
|
|
116
|
+
Owner: ['Owner', deserializeOwner],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const deserializeChecksumAlgorithmList = (output: any[]) =>
|
|
120
|
+
output.map(entry => String(entry));
|
|
121
|
+
|
|
122
|
+
const deserializeOwner = (output: any) =>
|
|
123
|
+
map(output, { DisplayName: 'DisplayName', ID: 'ID' });
|
|
124
|
+
|
|
125
|
+
export const listObjectsV2 = composeServiceApi(
|
|
126
|
+
s3TransferHandler,
|
|
127
|
+
listObjectsV2Serializer,
|
|
128
|
+
listObjectsV2Deserializer,
|
|
129
|
+
{ ...defaultConfig, responseType: 'text' }
|
|
130
|
+
);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Endpoint,
|
|
6
|
+
HttpRequest,
|
|
7
|
+
HttpResponse,
|
|
8
|
+
parseMetadata,
|
|
9
|
+
} from '@aws-amplify/core/internals/aws-client-utils';
|
|
10
|
+
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
11
|
+
import type {
|
|
12
|
+
ListPartsCommandInput,
|
|
13
|
+
ListPartsCommandOutput,
|
|
14
|
+
CompletedPart,
|
|
15
|
+
} from './types';
|
|
16
|
+
import { defaultConfig } from './base';
|
|
17
|
+
import {
|
|
18
|
+
emptyArrayGuard,
|
|
19
|
+
serializeObjectSsecOptionsToHeaders,
|
|
20
|
+
map,
|
|
21
|
+
parseXmlBody,
|
|
22
|
+
parseXmlError,
|
|
23
|
+
s3TransferHandler,
|
|
24
|
+
deserializeNumber,
|
|
25
|
+
serializePathnameObjectKey,
|
|
26
|
+
} from './utils';
|
|
27
|
+
|
|
28
|
+
export type ListPartsInput = Pick<
|
|
29
|
+
ListPartsCommandInput,
|
|
30
|
+
| 'Bucket'
|
|
31
|
+
| 'Key'
|
|
32
|
+
| 'UploadId'
|
|
33
|
+
| 'SSECustomerAlgorithm'
|
|
34
|
+
| 'SSECustomerKey'
|
|
35
|
+
// TODO(AllanZhengYP): remove in V6.
|
|
36
|
+
| 'SSECustomerKeyMD5'
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
export type ListPartsOutput = Pick<
|
|
40
|
+
ListPartsCommandOutput,
|
|
41
|
+
'Parts' | 'UploadId' | '$metadata'
|
|
42
|
+
>;
|
|
43
|
+
|
|
44
|
+
const listPartsSerializer = async (
|
|
45
|
+
input: ListPartsInput,
|
|
46
|
+
endpoint: Endpoint
|
|
47
|
+
): Promise<HttpRequest> => {
|
|
48
|
+
const headers = await serializeObjectSsecOptionsToHeaders(input);
|
|
49
|
+
const url = new URL(endpoint.url.toString());
|
|
50
|
+
url.pathname = serializePathnameObjectKey(url, input.Key);
|
|
51
|
+
url.search = new URLSearchParams({
|
|
52
|
+
uploadId: input.UploadId,
|
|
53
|
+
}).toString();
|
|
54
|
+
return {
|
|
55
|
+
method: 'GET',
|
|
56
|
+
headers,
|
|
57
|
+
url,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const listPartsDeserializer = async (
|
|
62
|
+
response: HttpResponse
|
|
63
|
+
): Promise<ListPartsOutput> => {
|
|
64
|
+
if (response.statusCode >= 300) {
|
|
65
|
+
const error = await parseXmlError(response);
|
|
66
|
+
throw error;
|
|
67
|
+
} else {
|
|
68
|
+
const parsed = await parseXmlBody(response);
|
|
69
|
+
const contents = map(parsed, {
|
|
70
|
+
UploadId: 'UploadId',
|
|
71
|
+
Parts: [
|
|
72
|
+
'Part',
|
|
73
|
+
value => emptyArrayGuard(value, deserializeCompletedPartList),
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
$metadata: parseMetadata(response),
|
|
78
|
+
...contents,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const deserializeCompletedPartList = (input: any[]): CompletedPart[] =>
|
|
84
|
+
input.map(item =>
|
|
85
|
+
map(item, {
|
|
86
|
+
PartNumber: ['PartNumber', deserializeNumber],
|
|
87
|
+
ETag: 'ETag',
|
|
88
|
+
Size: ['Size', deserializeNumber],
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
export const listParts = composeServiceApi(
|
|
93
|
+
s3TransferHandler,
|
|
94
|
+
listPartsSerializer,
|
|
95
|
+
listPartsDeserializer,
|
|
96
|
+
{ ...defaultConfig, responseType: 'text' }
|
|
97
|
+
);
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Endpoint,
|
|
6
|
+
HttpRequest,
|
|
7
|
+
HttpResponse,
|
|
8
|
+
parseMetadata,
|
|
9
|
+
} from '@aws-amplify/core/internals/aws-client-utils';
|
|
10
|
+
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';
|
|
11
|
+
|
|
12
|
+
import { defaultConfig } from './base';
|
|
13
|
+
import type { PutObjectCommandInput, PutObjectCommandOutput } from './types';
|
|
14
|
+
import {
|
|
15
|
+
assignStringVariables,
|
|
16
|
+
map,
|
|
17
|
+
parseXmlError,
|
|
18
|
+
s3TransferHandler,
|
|
19
|
+
serializeObjectConfigsToHeaders,
|
|
20
|
+
serializePathnameObjectKey,
|
|
21
|
+
} from './utils';
|
|
22
|
+
import type { S3ProviderPutConfig } from '../../types';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Reference: {@link S3ProviderPutConfig}
|
|
26
|
+
*/
|
|
27
|
+
export type PutObjectInput = Pick<
|
|
28
|
+
PutObjectCommandInput,
|
|
29
|
+
| 'Bucket'
|
|
30
|
+
| 'Key'
|
|
31
|
+
| 'Body'
|
|
32
|
+
| 'ServerSideEncryption'
|
|
33
|
+
| 'SSECustomerAlgorithm'
|
|
34
|
+
| 'SSECustomerKey'
|
|
35
|
+
// TODO(AllanZhengYP): remove in V6.
|
|
36
|
+
| 'SSECustomerKeyMD5'
|
|
37
|
+
| 'SSEKMSKeyId'
|
|
38
|
+
| 'ACL'
|
|
39
|
+
| 'CacheControl'
|
|
40
|
+
| 'ContentDisposition'
|
|
41
|
+
| 'ContentEncoding'
|
|
42
|
+
| 'ContentType'
|
|
43
|
+
| 'ContentMD5'
|
|
44
|
+
| 'Expires'
|
|
45
|
+
| 'Metadata'
|
|
46
|
+
| 'Tagging'
|
|
47
|
+
>;
|
|
48
|
+
|
|
49
|
+
export type PutObjectOutput = Pick<
|
|
50
|
+
PutObjectCommandOutput,
|
|
51
|
+
// PutObject output is not exposed in public API, but only logged in the debug mode
|
|
52
|
+
// so we only expose $metadata, ETag and VersionId for debug purpose.
|
|
53
|
+
'$metadata' | 'ETag' | 'VersionId'
|
|
54
|
+
>;
|
|
55
|
+
|
|
56
|
+
const putObjectSerializer = async (
|
|
57
|
+
input: PutObjectInput,
|
|
58
|
+
endpoint: Endpoint
|
|
59
|
+
): Promise<HttpRequest> => {
|
|
60
|
+
const headers = {
|
|
61
|
+
...(await serializeObjectConfigsToHeaders({
|
|
62
|
+
...input,
|
|
63
|
+
ContentType: input.ContentType ?? 'application/octet-stream',
|
|
64
|
+
})),
|
|
65
|
+
...assignStringVariables({ 'content-md5': input.ContentMD5 }),
|
|
66
|
+
};
|
|
67
|
+
const url = new URL(endpoint.url.toString());
|
|
68
|
+
url.pathname = serializePathnameObjectKey(url, input.Key);
|
|
69
|
+
return {
|
|
70
|
+
method: 'PUT',
|
|
71
|
+
headers,
|
|
72
|
+
url,
|
|
73
|
+
body: input.Body,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const putObjectDeserializer = async (
|
|
78
|
+
response: HttpResponse
|
|
79
|
+
): Promise<PutObjectOutput> => {
|
|
80
|
+
if (response.statusCode >= 300) {
|
|
81
|
+
const error = await parseXmlError(response);
|
|
82
|
+
throw error;
|
|
83
|
+
} else {
|
|
84
|
+
return {
|
|
85
|
+
...map(response.headers, {
|
|
86
|
+
ETag: 'etag',
|
|
87
|
+
VersionId: 'x-amz-version-id',
|
|
88
|
+
}),
|
|
89
|
+
$metadata: parseMetadata(response),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const putObject = composeServiceApi(
|
|
95
|
+
s3TransferHandler,
|
|
96
|
+
putObjectSerializer,
|
|
97
|
+
putObjectDeserializer,
|
|
98
|
+
{ ...defaultConfig, responseType: 'text' }
|
|
99
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
function bytesToBase64(bytes: Uint8Array): string {
|
|
5
|
+
const base64Str = Array.from(bytes, x => String.fromCodePoint(x)).join('');
|
|
6
|
+
return btoa(base64Str);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function utf8Encode(input: string): Uint8Array {
|
|
10
|
+
return new TextEncoder().encode(input);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function toBase64(input: string | ArrayBufferView): string {
|
|
14
|
+
if (typeof input === 'string') {
|
|
15
|
+
return bytesToBase64(utf8Encode(input));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return bytesToBase64(
|
|
19
|
+
new Uint8Array(input.buffer, input.byteOffset, input.byteLength)
|
|
20
|
+
);
|
|
21
|
+
}
|