@aws-amplify/storage 6.0.28 → 6.0.29-gen2-storage.e54bfa9.0
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/dist/cjs/errors/types/validation.js +22 -2
- package/dist/cjs/errors/types/validation.js.map +1 -1
- package/dist/cjs/providers/s3/apis/copy.js +2 -12
- package/dist/cjs/providers/s3/apis/copy.js.map +1 -1
- package/dist/cjs/providers/s3/apis/downloadData.js +13 -38
- package/dist/cjs/providers/s3/apis/downloadData.js.map +1 -1
- package/dist/cjs/providers/s3/apis/getProperties.js +2 -11
- package/dist/cjs/providers/s3/apis/getProperties.js.map +1 -1
- package/dist/cjs/providers/s3/apis/getUrl.js +2 -18
- package/dist/cjs/providers/s3/apis/getUrl.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/copy.js +41 -7
- package/dist/cjs/providers/s3/apis/internal/copy.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/getProperties.js +10 -6
- package/dist/cjs/providers/s3/apis/internal/getProperties.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/getUrl.js +8 -6
- package/dist/cjs/providers/s3/apis/internal/getUrl.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/list.js +86 -16
- package/dist/cjs/providers/s3/apis/internal/list.js.map +1 -1
- package/dist/cjs/providers/s3/apis/internal/remove.js +20 -7
- package/dist/cjs/providers/s3/apis/internal/remove.js.map +1 -1
- package/dist/cjs/providers/s3/apis/list.js +4 -4
- package/dist/cjs/providers/s3/apis/list.js.map +1 -1
- package/dist/cjs/providers/s3/apis/remove.js +2 -9
- package/dist/cjs/providers/s3/apis/remove.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/copy.js +4 -4
- package/dist/cjs/providers/s3/apis/server/copy.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/getProperties.js +2 -2
- package/dist/cjs/providers/s3/apis/server/getProperties.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/getUrl.js +2 -2
- package/dist/cjs/providers/s3/apis/server/getUrl.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/list.js +4 -4
- package/dist/cjs/providers/s3/apis/server/list.js.map +1 -1
- package/dist/cjs/providers/s3/apis/server/remove.js +2 -2
- package/dist/cjs/providers/s3/apis/server/remove.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/index.js +4 -50
- package/dist/cjs/providers/s3/apis/uploadData/index.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/initialUpload.js +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/initialUpload.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadCache.js +8 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadCache.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadHandlers.js +28 -13
- package/dist/cjs/providers/s3/apis/uploadData/multipart/uploadHandlers.js.map +1 -1
- package/dist/cjs/providers/s3/apis/uploadData/putObjectJob.js +10 -5
- package/dist/cjs/providers/s3/apis/uploadData/putObjectJob.js.map +1 -1
- package/dist/cjs/providers/s3/utils/client/utils/parsePayload.js +1 -1
- package/dist/cjs/providers/s3/utils/client/utils/parsePayload.js.map +1 -1
- package/dist/cjs/providers/s3/utils/constants.js +4 -1
- package/dist/cjs/providers/s3/utils/constants.js.map +1 -1
- package/dist/cjs/providers/s3/utils/index.js +7 -1
- package/dist/cjs/providers/s3/utils/index.js.map +1 -1
- package/dist/cjs/providers/s3/utils/isInputWithPath.js +11 -0
- package/dist/cjs/providers/s3/utils/isInputWithPath.js.map +1 -0
- package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js +2 -1
- package/dist/cjs/providers/s3/utils/resolveS3ConfigAndInput.js.map +1 -1
- package/dist/cjs/providers/s3/utils/validateStorageOperationInput.js +31 -0
- package/dist/cjs/providers/s3/utils/validateStorageOperationInput.js.map +1 -0
- package/dist/cjs/providers/s3/utils/validateStorageOperationInputWithPrefix.js +32 -0
- package/dist/cjs/providers/s3/utils/validateStorageOperationInputWithPrefix.js.map +1 -0
- package/dist/esm/errors/types/validation.d.ts +7 -2
- package/dist/esm/errors/types/validation.mjs +22 -2
- package/dist/esm/errors/types/validation.mjs.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/providers/s3/apis/copy.d.ts +22 -9
- package/dist/esm/providers/s3/apis/copy.mjs +2 -12
- package/dist/esm/providers/s3/apis/copy.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/downloadData.d.ts +41 -7
- package/dist/esm/providers/s3/apis/downloadData.mjs +15 -39
- package/dist/esm/providers/s3/apis/downloadData.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/getProperties.d.ts +18 -5
- package/dist/esm/providers/s3/apis/getProperties.mjs +2 -11
- package/dist/esm/providers/s3/apis/getProperties.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/getUrl.d.ts +27 -7
- package/dist/esm/providers/s3/apis/getUrl.mjs +2 -18
- package/dist/esm/providers/s3/apis/getUrl.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/copy.d.ts +4 -2
- package/dist/esm/providers/s3/apis/internal/copy.mjs +41 -6
- package/dist/esm/providers/s3/apis/internal/copy.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/getProperties.d.ts +2 -2
- package/dist/esm/providers/s3/apis/internal/getProperties.mjs +11 -6
- package/dist/esm/providers/s3/apis/internal/getProperties.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/getUrl.d.ts +2 -2
- package/dist/esm/providers/s3/apis/internal/getUrl.mjs +10 -7
- package/dist/esm/providers/s3/apis/internal/getUrl.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/list.d.ts +2 -2
- package/dist/esm/providers/s3/apis/internal/list.mjs +87 -16
- package/dist/esm/providers/s3/apis/internal/list.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/internal/remove.d.ts +2 -2
- package/dist/esm/providers/s3/apis/internal/remove.mjs +21 -7
- package/dist/esm/providers/s3/apis/internal/remove.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/list.d.ts +39 -22
- package/dist/esm/providers/s3/apis/list.mjs +2 -2
- package/dist/esm/providers/s3/apis/list.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/remove.d.ts +18 -5
- package/dist/esm/providers/s3/apis/remove.mjs +2 -9
- package/dist/esm/providers/s3/apis/remove.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/copy.d.ts +27 -2
- package/dist/esm/providers/s3/apis/server/copy.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/copy.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/getProperties.d.ts +26 -2
- package/dist/esm/providers/s3/apis/server/getProperties.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/getProperties.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/getUrl.d.ts +40 -2
- package/dist/esm/providers/s3/apis/server/getUrl.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/getUrl.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/list.d.ts +41 -22
- package/dist/esm/providers/s3/apis/server/list.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/list.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/server/remove.d.ts +24 -2
- package/dist/esm/providers/s3/apis/server/remove.mjs +2 -2
- package/dist/esm/providers/s3/apis/server/remove.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/index.d.ts +64 -7
- package/dist/esm/providers/s3/apis/uploadData/index.mjs +4 -50
- package/dist/esm/providers/s3/apis/uploadData/index.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/initialUpload.d.ts +2 -2
- package/dist/esm/providers/s3/apis/uploadData/multipart/initialUpload.mjs +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/initialUpload.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadCache.d.ts +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadCache.mjs +8 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadCache.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.d.ts +4 -4
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.mjs +30 -14
- package/dist/esm/providers/s3/apis/uploadData/multipart/uploadHandlers.mjs.map +1 -1
- package/dist/esm/providers/s3/apis/uploadData/putObjectJob.d.ts +3 -3
- package/dist/esm/providers/s3/apis/uploadData/putObjectJob.mjs +11 -5
- package/dist/esm/providers/s3/apis/uploadData/putObjectJob.mjs.map +1 -1
- package/dist/esm/providers/s3/index.d.ts +2 -2
- package/dist/esm/providers/s3/types/index.d.ts +3 -3
- package/dist/esm/providers/s3/types/inputs.d.ts +51 -11
- package/dist/esm/providers/s3/types/options.d.ts +41 -10
- package/dist/esm/providers/s3/types/outputs.d.ts +68 -13
- package/dist/esm/providers/s3/utils/client/utils/parsePayload.mjs +1 -1
- package/dist/esm/providers/s3/utils/client/utils/parsePayload.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/constants.d.ts +3 -0
- package/dist/esm/providers/s3/utils/constants.mjs +4 -1
- package/dist/esm/providers/s3/utils/constants.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/index.d.ts +3 -0
- package/dist/esm/providers/s3/utils/index.mjs +3 -0
- package/dist/esm/providers/s3/utils/index.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/isInputWithPath.d.ts +2 -0
- package/dist/esm/providers/s3/utils/isInputWithPath.mjs +8 -0
- package/dist/esm/providers/s3/utils/isInputWithPath.mjs.map +1 -0
- package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.d.ts +2 -1
- package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs +2 -1
- package/dist/esm/providers/s3/utils/resolveS3ConfigAndInput.mjs.map +1 -1
- package/dist/esm/providers/s3/utils/validateStorageOperationInput.d.ts +5 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInput.mjs +29 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInput.mjs.map +1 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInputWithPrefix.d.ts +5 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInputWithPrefix.mjs +30 -0
- package/dist/esm/providers/s3/utils/validateStorageOperationInputWithPrefix.mjs.map +1 -0
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/inputs.d.ts +41 -13
- package/dist/esm/types/options.d.ts +1 -0
- package/dist/esm/types/outputs.d.ts +26 -6
- package/package.json +107 -107
- package/src/errors/types/validation.ts +23 -2
- package/src/index.ts +16 -0
- package/src/providers/s3/apis/copy.ts +30 -11
- package/src/providers/s3/apis/downloadData.ts +78 -19
- package/src/providers/s3/apis/getProperties.ts +31 -8
- package/src/providers/s3/apis/getUrl.ts +37 -10
- package/src/providers/s3/apis/internal/copy.ts +89 -8
- package/src/providers/s3/apis/internal/getProperties.ts +27 -12
- package/src/providers/s3/apis/internal/getUrl.ts +28 -14
- package/src/providers/s3/apis/internal/list.ts +135 -29
- package/src/providers/s3/apis/internal/remove.ts +36 -13
- package/src/providers/s3/apis/list.ts +54 -26
- package/src/providers/s3/apis/remove.ts +28 -7
- package/src/providers/s3/apis/server/copy.ts +42 -5
- package/src/providers/s3/apis/server/getProperties.ts +41 -4
- package/src/providers/s3/apis/server/getUrl.ts +55 -4
- package/src/providers/s3/apis/server/list.ts +64 -32
- package/src/providers/s3/apis/server/remove.ts +39 -4
- package/src/providers/s3/apis/uploadData/index.ts +77 -8
- package/src/providers/s3/apis/uploadData/multipart/initialUpload.ts +4 -3
- package/src/providers/s3/apis/uploadData/multipart/uploadCache.ts +11 -2
- package/src/providers/s3/apis/uploadData/multipart/uploadHandlers.ts +50 -20
- package/src/providers/s3/apis/uploadData/putObjectJob.ts +23 -9
- package/src/providers/s3/index.ts +16 -0
- package/src/providers/s3/types/index.ts +37 -14
- package/src/providers/s3/types/inputs.ts +95 -26
- package/src/providers/s3/types/options.ts +73 -27
- package/src/providers/s3/types/outputs.ts +80 -13
- package/src/providers/s3/utils/client/utils/parsePayload.ts +1 -1
- package/src/providers/s3/utils/constants.ts +4 -0
- package/src/providers/s3/utils/index.ts +3 -0
- package/src/providers/s3/utils/isInputWithPath.ts +13 -0
- package/src/providers/s3/utils/resolveS3ConfigAndInput.ts +3 -2
- package/src/providers/s3/utils/validateStorageOperationInput.ts +39 -0
- package/src/providers/s3/utils/validateStorageOperationInputWithPrefix.ts +46 -0
- package/src/types/index.ts +16 -8
- package/src/types/inputs.ts +73 -20
- package/src/types/options.ts +1 -0
- package/src/types/outputs.ts +29 -6
package/src/index.ts
CHANGED
|
@@ -13,24 +13,40 @@ export {
|
|
|
13
13
|
|
|
14
14
|
export {
|
|
15
15
|
UploadDataInput,
|
|
16
|
+
UploadDataWithPathInput,
|
|
16
17
|
DownloadDataInput,
|
|
18
|
+
DownloadDataWithPathInput,
|
|
17
19
|
RemoveInput,
|
|
20
|
+
RemoveWithPathInput,
|
|
18
21
|
ListAllInput,
|
|
22
|
+
ListAllWithPathInput,
|
|
19
23
|
ListPaginateInput,
|
|
24
|
+
ListPaginateWithPathInput,
|
|
20
25
|
GetPropertiesInput,
|
|
26
|
+
GetPropertiesWithPathInput,
|
|
21
27
|
CopyInput,
|
|
28
|
+
CopyWithPathInput,
|
|
22
29
|
GetUrlInput,
|
|
30
|
+
GetUrlWithPathInput,
|
|
23
31
|
} from './providers/s3/types/inputs';
|
|
24
32
|
|
|
25
33
|
export {
|
|
26
34
|
UploadDataOutput,
|
|
35
|
+
UploadDataWithPathOutput,
|
|
27
36
|
DownloadDataOutput,
|
|
37
|
+
DownloadDataWithPathOutput,
|
|
28
38
|
RemoveOutput,
|
|
39
|
+
RemoveWithPathOutput,
|
|
29
40
|
ListAllOutput,
|
|
41
|
+
ListAllWithPathOutput,
|
|
30
42
|
ListPaginateOutput,
|
|
43
|
+
ListPaginateWithPathOutput,
|
|
31
44
|
GetPropertiesOutput,
|
|
45
|
+
GetPropertiesWithPathOutput,
|
|
32
46
|
CopyOutput,
|
|
47
|
+
CopyWithPathOutput,
|
|
33
48
|
GetUrlOutput,
|
|
49
|
+
GetUrlWithPathOutput,
|
|
34
50
|
} from './providers/s3/types/outputs';
|
|
35
51
|
|
|
36
52
|
export { TransferProgressEvent } from './types';
|
|
@@ -3,21 +3,40 @@
|
|
|
3
3
|
|
|
4
4
|
import { Amplify } from '@aws-amplify/core';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
CopyInput,
|
|
8
|
+
CopyOutput,
|
|
9
|
+
CopyWithPathInput,
|
|
10
|
+
CopyWithPathOutput,
|
|
11
|
+
} from '../types';
|
|
8
12
|
|
|
9
13
|
import { copy as copyInternal } from './internal/copy';
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
|
-
* Copy an object from a source
|
|
13
|
-
* different level or identityId (if source object's level is 'protected').
|
|
16
|
+
* Copy an object from a source to a destination object within the same bucket.
|
|
14
17
|
*
|
|
15
|
-
* @param input - The
|
|
16
|
-
* @returns Output containing the destination
|
|
17
|
-
* @throws service:
|
|
18
|
-
* @throws validation:
|
|
19
|
-
* source or destination
|
|
18
|
+
* @param input - The `CopyWithPathInput` object.
|
|
19
|
+
* @returns Output containing the destination object path.
|
|
20
|
+
* @throws service: `S3Exception` - Thrown when checking for existence of the object
|
|
21
|
+
* @throws validation: `StorageValidationErrorCode` - Thrown when
|
|
22
|
+
* source or destination path is not defined.
|
|
20
23
|
*/
|
|
21
|
-
export
|
|
24
|
+
export function copy(input: CopyWithPathInput): Promise<CopyWithPathOutput>;
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
27
|
+
* Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/copy | path} instead.
|
|
28
|
+
*
|
|
29
|
+
* Copy an object from a source to a destination object within the same bucket. Can optionally copy files across
|
|
30
|
+
* different accessLevel or identityId (if source object's accessLevel is 'protected').
|
|
31
|
+
*
|
|
32
|
+
* @param input - The `CopyInput` object.
|
|
33
|
+
* @returns Output containing the destination object key.
|
|
34
|
+
* @throws service: `S3Exception` - Thrown when checking for existence of the object
|
|
35
|
+
* @throws validation: `StorageValidationErrorCode` - Thrown when
|
|
36
|
+
* source or destination key is not defined.
|
|
37
|
+
*/
|
|
38
|
+
export function copy(input: CopyInput): Promise<CopyOutput>;
|
|
39
|
+
|
|
40
|
+
export function copy(input: CopyInput | CopyWithPathInput) {
|
|
22
41
|
return copyInternal(Amplify, input);
|
|
23
|
-
}
|
|
42
|
+
}
|
|
@@ -4,33 +4,43 @@
|
|
|
4
4
|
import { Amplify } from '@aws-amplify/core';
|
|
5
5
|
import { StorageAction } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
DownloadDataInput,
|
|
9
|
+
DownloadDataOutput,
|
|
10
|
+
DownloadDataWithPathInput,
|
|
11
|
+
DownloadDataWithPathOutput,
|
|
12
|
+
} from '../types';
|
|
8
13
|
import { resolveS3ConfigAndInput } from '../utils/resolveS3ConfigAndInput';
|
|
9
|
-
import {
|
|
10
|
-
import { createDownloadTask } from '../utils';
|
|
14
|
+
import { createDownloadTask, validateStorageOperationInput } from '../utils';
|
|
11
15
|
import { getObject } from '../utils/client';
|
|
12
16
|
import { getStorageUserAgentValue } from '../utils/userAgent';
|
|
13
17
|
import { logger } from '../../../utils';
|
|
18
|
+
import {
|
|
19
|
+
StorageDownloadDataOutput,
|
|
20
|
+
StorageItemWithKey,
|
|
21
|
+
StorageItemWithPath,
|
|
22
|
+
} from '../../../types';
|
|
23
|
+
import { STORAGE_INPUT_KEY } from '../utils/constants';
|
|
14
24
|
|
|
15
25
|
/**
|
|
16
26
|
* Download S3 object data to memory
|
|
17
27
|
*
|
|
18
|
-
* @param input - The
|
|
28
|
+
* @param input - The `DownloadDataWithPathInput` object.
|
|
19
29
|
* @returns A cancelable task exposing result promise from `result` property.
|
|
20
|
-
* @throws service:
|
|
21
|
-
* @throws validation:
|
|
30
|
+
* @throws service: `S3Exception` - thrown when checking for existence of the object
|
|
31
|
+
* @throws validation: `StorageValidationErrorCode` - Validation errors
|
|
22
32
|
*
|
|
23
33
|
* @example
|
|
24
34
|
* ```ts
|
|
25
35
|
* // Download a file from s3 bucket
|
|
26
|
-
* const { body, eTag } = await downloadData({
|
|
36
|
+
* const { body, eTag } = await downloadData({ path, options: {
|
|
27
37
|
* onProgress, // Optional progress callback.
|
|
28
38
|
* } }).result;
|
|
29
39
|
* ```
|
|
30
40
|
* @example
|
|
31
41
|
* ```ts
|
|
32
42
|
* // Cancel a task
|
|
33
|
-
* const downloadTask = downloadData({
|
|
43
|
+
* const downloadTask = downloadData({ path });
|
|
34
44
|
* //...
|
|
35
45
|
* downloadTask.cancel();
|
|
36
46
|
* try {
|
|
@@ -42,7 +52,47 @@ import { logger } from '../../../utils';
|
|
|
42
52
|
* }
|
|
43
53
|
*```
|
|
44
54
|
*/
|
|
45
|
-
export
|
|
55
|
+
export function downloadData(
|
|
56
|
+
input: DownloadDataWithPathInput,
|
|
57
|
+
): DownloadDataWithPathOutput;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
60
|
+
* Please use {@link https://docs.amplify.aws/react/build-a-backend/storage/download/#downloaddata | path} instead.
|
|
61
|
+
*
|
|
62
|
+
* Download S3 object data to memory
|
|
63
|
+
*
|
|
64
|
+
* @param input - The `DownloadDataInput` object.
|
|
65
|
+
* @returns A cancelable task exposing result promise from `result` property.
|
|
66
|
+
* @throws service: `S3Exception` - thrown when checking for existence of the object
|
|
67
|
+
* @throws validation: `StorageValidationErrorCode` - Validation errors
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* // Download a file from s3 bucket
|
|
72
|
+
* const { body, eTag } = await downloadData({ key, options: {
|
|
73
|
+
* onProgress, // Optional progress callback.
|
|
74
|
+
* } }).result;
|
|
75
|
+
* ```
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* // Cancel a task
|
|
79
|
+
* const downloadTask = downloadData({ key });
|
|
80
|
+
* //...
|
|
81
|
+
* downloadTask.cancel();
|
|
82
|
+
* try {
|
|
83
|
+
* await downloadTask.result;
|
|
84
|
+
* } catch (error) {
|
|
85
|
+
* if(isCancelError(error)) {
|
|
86
|
+
* // Handle error thrown by task cancelation.
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
*```
|
|
90
|
+
*/
|
|
91
|
+
export function downloadData(input: DownloadDataInput): DownloadDataOutput;
|
|
92
|
+
|
|
93
|
+
export function downloadData(
|
|
94
|
+
input: DownloadDataInput | DownloadDataWithPathInput,
|
|
95
|
+
) {
|
|
46
96
|
const abortController = new AbortController();
|
|
47
97
|
|
|
48
98
|
const downloadTask = createDownloadTask({
|
|
@@ -53,21 +103,27 @@ export const downloadData = (input: DownloadDataInput): DownloadDataOutput => {
|
|
|
53
103
|
});
|
|
54
104
|
|
|
55
105
|
return downloadTask;
|
|
56
|
-
}
|
|
106
|
+
}
|
|
57
107
|
|
|
58
108
|
const downloadDataJob =
|
|
59
109
|
(
|
|
60
|
-
|
|
110
|
+
downloadDataInput: DownloadDataInput | DownloadDataWithPathInput,
|
|
61
111
|
abortSignal: AbortSignal,
|
|
62
112
|
) =>
|
|
63
|
-
async ()
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
113
|
+
async (): Promise<
|
|
114
|
+
StorageDownloadDataOutput<StorageItemWithKey | StorageItemWithPath>
|
|
115
|
+
> => {
|
|
116
|
+
const { options: downloadDataOptions } = downloadDataInput;
|
|
117
|
+
const { bucket, keyPrefix, s3Config, identityId } =
|
|
118
|
+
await resolveS3ConfigAndInput(Amplify, downloadDataOptions);
|
|
119
|
+
const { inputType, objectKey } = validateStorageOperationInput(
|
|
120
|
+
downloadDataInput,
|
|
121
|
+
identityId,
|
|
67
122
|
);
|
|
68
|
-
const finalKey =
|
|
123
|
+
const finalKey =
|
|
124
|
+
inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;
|
|
69
125
|
|
|
70
|
-
logger.debug(`download ${
|
|
126
|
+
logger.debug(`download ${objectKey} from ${finalKey}.`);
|
|
71
127
|
|
|
72
128
|
const {
|
|
73
129
|
Body: body,
|
|
@@ -93,8 +149,7 @@ const downloadDataJob =
|
|
|
93
149
|
},
|
|
94
150
|
);
|
|
95
151
|
|
|
96
|
-
|
|
97
|
-
key,
|
|
152
|
+
const result = {
|
|
98
153
|
body,
|
|
99
154
|
lastModified,
|
|
100
155
|
size,
|
|
@@ -103,4 +158,8 @@ const downloadDataJob =
|
|
|
103
158
|
metadata,
|
|
104
159
|
versionId,
|
|
105
160
|
};
|
|
161
|
+
|
|
162
|
+
return inputType === STORAGE_INPUT_KEY
|
|
163
|
+
? { key: objectKey, ...result }
|
|
164
|
+
: { path: objectKey, ...result };
|
|
106
165
|
};
|
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import { Amplify } from '@aws-amplify/core';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
GetPropertiesInput,
|
|
8
|
+
GetPropertiesOutput,
|
|
9
|
+
GetPropertiesWithPathInput,
|
|
10
|
+
GetPropertiesWithPathOutput,
|
|
11
|
+
} from '../types';
|
|
8
12
|
|
|
9
13
|
import { getProperties as getPropertiesInternal } from './internal/getProperties';
|
|
10
14
|
|
|
@@ -12,13 +16,32 @@ import { getProperties as getPropertiesInternal } from './internal/getProperties
|
|
|
12
16
|
* Gets the properties of a file. The properties include S3 system metadata and
|
|
13
17
|
* the user metadata that was provided when uploading the file.
|
|
14
18
|
*
|
|
15
|
-
* @param input - The
|
|
19
|
+
* @param input - The `GetPropertiesWithPathInput` object.
|
|
16
20
|
* @returns Requested object properties.
|
|
17
|
-
* @throws
|
|
18
|
-
* @throws A
|
|
21
|
+
* @throws An `S3Exception` when the underlying S3 service returned error.
|
|
22
|
+
* @throws A `StorageValidationErrorCode` when API call parameters are invalid.
|
|
19
23
|
*/
|
|
20
|
-
export
|
|
24
|
+
export function getProperties(
|
|
25
|
+
input: GetPropertiesWithPathInput,
|
|
26
|
+
): Promise<GetPropertiesWithPathOutput>;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
29
|
+
* Please use {@link https://docs.amplify.aws/javascript/build-a-backend/storage/get-properties/ | path} instead.
|
|
30
|
+
*
|
|
31
|
+
* Gets the properties of a file. The properties include S3 system metadata and
|
|
32
|
+
* the user metadata that was provided when uploading the file.
|
|
33
|
+
*
|
|
34
|
+
* @param input - The `GetPropertiesInput` object.
|
|
35
|
+
* @returns Requested object properties.
|
|
36
|
+
* @throws An `S3Exception` when the underlying S3 service returned error.
|
|
37
|
+
* @throws A `StorageValidationErrorCode` when API call parameters are invalid.
|
|
38
|
+
*/
|
|
39
|
+
export function getProperties(
|
|
21
40
|
input: GetPropertiesInput,
|
|
22
|
-
): Promise<GetPropertiesOutput
|
|
41
|
+
): Promise<GetPropertiesOutput>;
|
|
42
|
+
|
|
43
|
+
export function getProperties(
|
|
44
|
+
input: GetPropertiesInput | GetPropertiesWithPathInput,
|
|
45
|
+
) {
|
|
23
46
|
return getPropertiesInternal(Amplify, input);
|
|
24
|
-
}
|
|
47
|
+
}
|
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import { Amplify } from '@aws-amplify/core';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import {
|
|
7
|
+
GetUrlInput,
|
|
8
|
+
GetUrlOutput,
|
|
9
|
+
GetUrlWithPathInput,
|
|
10
|
+
GetUrlWithPathOutput,
|
|
11
|
+
} from '../types';
|
|
9
12
|
|
|
10
13
|
import { getUrl as getUrlInternal } from './internal/getUrl';
|
|
11
14
|
|
|
@@ -16,15 +19,39 @@ import { getUrl as getUrlInternal } from './internal/getUrl';
|
|
|
16
19
|
*
|
|
17
20
|
* By default, it will not validate the object that exists in S3. If you set the `options.validateObjectExistence`
|
|
18
21
|
* to true, this method will verify the given object already exists in S3 before returning a presigned
|
|
19
|
-
* URL, and will throw
|
|
22
|
+
* URL, and will throw `StorageError` if the object does not exist.
|
|
20
23
|
*
|
|
21
|
-
* @param input - The
|
|
22
|
-
* @returns Presigned URL and timestamp when the URL
|
|
23
|
-
* @throws service:
|
|
24
|
-
* @throws validation:
|
|
24
|
+
* @param input - The `GetUrlWithPathInput` object.
|
|
25
|
+
* @returns Presigned URL and timestamp when the URL may expire.
|
|
26
|
+
* @throws service: `S3Exception` - thrown when checking for existence of the object
|
|
27
|
+
* @throws validation: `StorageValidationErrorCode` - Validation errors
|
|
25
28
|
* thrown either username or key are not defined.
|
|
26
29
|
*
|
|
27
30
|
*/
|
|
28
|
-
export
|
|
31
|
+
export function getUrl(
|
|
32
|
+
input: GetUrlWithPathInput,
|
|
33
|
+
): Promise<GetUrlWithPathOutput>;
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated The `key` and `accessLevel` parameters are deprecated and may be removed in the next major version.
|
|
36
|
+
* Please use {@link https://docs.amplify.aws/javascript/build-a-backend/storage/download/#generate-a-download-url | path} instead.
|
|
37
|
+
*
|
|
38
|
+
* Get a temporary presigned URL to download the specified S3 object.
|
|
39
|
+
* The presigned URL expires when the associated role used to sign the request expires or
|
|
40
|
+
* the option `expiresIn` is reached. The `expiresAt` property in the output object indicates when the URL MAY expire.
|
|
41
|
+
*
|
|
42
|
+
* By default, it will not validate the object that exists in S3. If you set the `options.validateObjectExistence`
|
|
43
|
+
* to true, this method will verify the given object already exists in S3 before returning a presigned
|
|
44
|
+
* URL, and will throw `StorageError` if the object does not exist.
|
|
45
|
+
*
|
|
46
|
+
* @param input - The `GetUrlInput` object.
|
|
47
|
+
* @returns Presigned URL and timestamp when the URL may expire.
|
|
48
|
+
* @throws service: `S3Exception` - thrown when checking for existence of the object
|
|
49
|
+
* @throws validation: `StorageValidationErrorCode` - Validation errors
|
|
50
|
+
* thrown either username or key are not defined.
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
export function getUrl(input: GetUrlInput): Promise<GetUrlOutput>;
|
|
54
|
+
|
|
55
|
+
export function getUrl(input: GetUrlInput | GetUrlWithPathInput) {
|
|
29
56
|
return getUrlInternal(Amplify, input);
|
|
30
|
-
}
|
|
57
|
+
}
|
|
@@ -4,15 +4,76 @@
|
|
|
4
4
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
5
5
|
import { StorageAction } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
CopyInput,
|
|
9
|
+
CopyOutput,
|
|
10
|
+
CopyWithPathInput,
|
|
11
|
+
CopyWithPathOutput,
|
|
12
|
+
} from '../../types';
|
|
13
|
+
import { ResolvedS3Config } from '../../types/options';
|
|
14
|
+
import {
|
|
15
|
+
isInputWithPath,
|
|
16
|
+
resolveS3ConfigAndInput,
|
|
17
|
+
validateStorageOperationInput,
|
|
18
|
+
} from '../../utils';
|
|
9
19
|
import { StorageValidationErrorCode } from '../../../../errors/types/validation';
|
|
10
20
|
import { assertValidationError } from '../../../../errors/utils/assertValidationError';
|
|
11
21
|
import { copyObject } from '../../utils/client';
|
|
12
22
|
import { getStorageUserAgentValue } from '../../utils/userAgent';
|
|
13
23
|
import { logger } from '../../../../utils';
|
|
14
24
|
|
|
25
|
+
const isCopyInputWithPath = (
|
|
26
|
+
input: CopyInput | CopyWithPathInput,
|
|
27
|
+
): input is CopyWithPathInput => isInputWithPath(input.source);
|
|
28
|
+
|
|
15
29
|
export const copy = async (
|
|
30
|
+
amplify: AmplifyClassV6,
|
|
31
|
+
input: CopyInput | CopyWithPathInput,
|
|
32
|
+
): Promise<CopyOutput | CopyWithPathOutput> => {
|
|
33
|
+
return isCopyInputWithPath(input)
|
|
34
|
+
? copyWithPath(amplify, input)
|
|
35
|
+
: copyWithKey(amplify, input);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const copyWithPath = async (
|
|
39
|
+
amplify: AmplifyClassV6,
|
|
40
|
+
input: CopyWithPathInput,
|
|
41
|
+
): Promise<CopyWithPathOutput> => {
|
|
42
|
+
const { source, destination } = input;
|
|
43
|
+
const { s3Config, bucket, identityId } =
|
|
44
|
+
await resolveS3ConfigAndInput(amplify);
|
|
45
|
+
|
|
46
|
+
assertValidationError(!!source.path, StorageValidationErrorCode.NoSourcePath);
|
|
47
|
+
assertValidationError(
|
|
48
|
+
!!destination.path,
|
|
49
|
+
StorageValidationErrorCode.NoDestinationPath,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const { objectKey: sourcePath } = validateStorageOperationInput(
|
|
53
|
+
source,
|
|
54
|
+
identityId,
|
|
55
|
+
);
|
|
56
|
+
const { objectKey: destinationPath } = validateStorageOperationInput(
|
|
57
|
+
destination,
|
|
58
|
+
identityId,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const finalCopySource = `${bucket}/${sourcePath}`;
|
|
62
|
+
const finalCopyDestination = destinationPath;
|
|
63
|
+
logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
|
|
64
|
+
|
|
65
|
+
await serviceCopy({
|
|
66
|
+
source: finalCopySource,
|
|
67
|
+
destination: finalCopyDestination,
|
|
68
|
+
bucket,
|
|
69
|
+
s3Config,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return { path: finalCopyDestination };
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** @deprecated Use {@link copyWithPath} instead. */
|
|
76
|
+
export const copyWithKey = async (
|
|
16
77
|
amplify: AmplifyClassV6,
|
|
17
78
|
input: CopyInput,
|
|
18
79
|
): Promise<CopyOutput> => {
|
|
@@ -41,6 +102,30 @@ export const copy = async (
|
|
|
41
102
|
const finalCopySource = `${bucket}/${sourceKeyPrefix}${sourceKey}`;
|
|
42
103
|
const finalCopyDestination = `${destinationKeyPrefix}${destinationKey}`;
|
|
43
104
|
logger.debug(`copying "${finalCopySource}" to "${finalCopyDestination}".`);
|
|
105
|
+
|
|
106
|
+
await serviceCopy({
|
|
107
|
+
source: finalCopySource,
|
|
108
|
+
destination: finalCopyDestination,
|
|
109
|
+
bucket,
|
|
110
|
+
s3Config,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
key: destinationKey,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const serviceCopy = async ({
|
|
119
|
+
source,
|
|
120
|
+
destination,
|
|
121
|
+
bucket,
|
|
122
|
+
s3Config,
|
|
123
|
+
}: {
|
|
124
|
+
source: string;
|
|
125
|
+
destination: string;
|
|
126
|
+
bucket: string;
|
|
127
|
+
s3Config: ResolvedS3Config;
|
|
128
|
+
}) => {
|
|
44
129
|
await copyObject(
|
|
45
130
|
{
|
|
46
131
|
...s3Config,
|
|
@@ -48,13 +133,9 @@ export const copy = async (
|
|
|
48
133
|
},
|
|
49
134
|
{
|
|
50
135
|
Bucket: bucket,
|
|
51
|
-
CopySource:
|
|
52
|
-
Key:
|
|
136
|
+
CopySource: source,
|
|
137
|
+
Key: destination,
|
|
53
138
|
MetadataDirective: 'COPY', // Copies over metadata like contentType as well
|
|
54
139
|
},
|
|
55
140
|
);
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
key: destinationKey,
|
|
59
|
-
};
|
|
60
141
|
};
|
|
@@ -4,25 +4,37 @@
|
|
|
4
4
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
5
5
|
import { StorageAction } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
GetPropertiesInput,
|
|
9
|
+
GetPropertiesOutput,
|
|
10
|
+
GetPropertiesWithPathInput,
|
|
11
|
+
GetPropertiesWithPathOutput,
|
|
12
|
+
} from '../../types';
|
|
13
|
+
import {
|
|
14
|
+
resolveS3ConfigAndInput,
|
|
15
|
+
validateStorageOperationInput,
|
|
16
|
+
} from '../../utils';
|
|
9
17
|
import { headObject } from '../../utils/client';
|
|
10
18
|
import { getStorageUserAgentValue } from '../../utils/userAgent';
|
|
11
19
|
import { logger } from '../../../../utils';
|
|
20
|
+
import { STORAGE_INPUT_KEY } from '../../utils/constants';
|
|
12
21
|
|
|
13
22
|
export const getProperties = async (
|
|
14
23
|
amplify: AmplifyClassV6,
|
|
15
|
-
input: GetPropertiesInput,
|
|
24
|
+
input: GetPropertiesInput | GetPropertiesWithPathInput,
|
|
16
25
|
action?: StorageAction,
|
|
17
|
-
): Promise<GetPropertiesOutput> => {
|
|
18
|
-
const {
|
|
19
|
-
const { s3Config, bucket, keyPrefix } =
|
|
20
|
-
amplify,
|
|
21
|
-
|
|
26
|
+
): Promise<GetPropertiesOutput | GetPropertiesWithPathOutput> => {
|
|
27
|
+
const { options: getPropertiesOptions } = input;
|
|
28
|
+
const { s3Config, bucket, keyPrefix, identityId } =
|
|
29
|
+
await resolveS3ConfigAndInput(amplify, getPropertiesOptions);
|
|
30
|
+
const { inputType, objectKey } = validateStorageOperationInput(
|
|
31
|
+
input,
|
|
32
|
+
identityId,
|
|
22
33
|
);
|
|
23
|
-
const finalKey =
|
|
34
|
+
const finalKey =
|
|
35
|
+
inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;
|
|
24
36
|
|
|
25
|
-
logger.debug(`get properties of ${
|
|
37
|
+
logger.debug(`get properties of ${objectKey} from ${finalKey}`);
|
|
26
38
|
const response = await headObject(
|
|
27
39
|
{
|
|
28
40
|
...s3Config,
|
|
@@ -36,8 +48,7 @@ export const getProperties = async (
|
|
|
36
48
|
},
|
|
37
49
|
);
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
key,
|
|
51
|
+
const result = {
|
|
41
52
|
contentType: response.ContentType,
|
|
42
53
|
size: response.ContentLength,
|
|
43
54
|
eTag: response.ETag,
|
|
@@ -45,4 +56,8 @@ export const getProperties = async (
|
|
|
45
56
|
metadata: response.Metadata,
|
|
46
57
|
versionId: response.VersionId,
|
|
47
58
|
};
|
|
59
|
+
|
|
60
|
+
return inputType === STORAGE_INPUT_KEY
|
|
61
|
+
? { key: objectKey, ...result }
|
|
62
|
+
: { path: objectKey, ...result };
|
|
48
63
|
};
|
|
@@ -4,34 +4,48 @@
|
|
|
4
4
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
5
5
|
import { StorageAction } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
GetUrlInput,
|
|
9
|
+
GetUrlOutput,
|
|
10
|
+
GetUrlWithPathInput,
|
|
11
|
+
GetUrlWithPathOutput,
|
|
12
|
+
} from '../../types';
|
|
8
13
|
import { StorageValidationErrorCode } from '../../../../errors/types/validation';
|
|
9
14
|
import { getPresignedGetObjectUrl } from '../../utils/client';
|
|
10
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
resolveS3ConfigAndInput,
|
|
17
|
+
validateStorageOperationInput,
|
|
18
|
+
} from '../../utils';
|
|
11
19
|
import { assertValidationError } from '../../../../errors/utils/assertValidationError';
|
|
12
20
|
import {
|
|
13
21
|
DEFAULT_PRESIGN_EXPIRATION,
|
|
14
22
|
MAX_URL_EXPIRATION,
|
|
23
|
+
STORAGE_INPUT_KEY,
|
|
15
24
|
} from '../../utils/constants';
|
|
16
25
|
|
|
17
26
|
import { getProperties } from './getProperties';
|
|
18
27
|
|
|
19
28
|
export const getUrl = async (
|
|
20
29
|
amplify: AmplifyClassV6,
|
|
21
|
-
input: GetUrlInput,
|
|
22
|
-
): Promise<GetUrlOutput> => {
|
|
23
|
-
const {
|
|
30
|
+
input: GetUrlInput | GetUrlWithPathInput,
|
|
31
|
+
): Promise<GetUrlOutput | GetUrlWithPathOutput> => {
|
|
32
|
+
const { options: getUrlOptions } = input;
|
|
33
|
+
const { s3Config, keyPrefix, bucket, identityId } =
|
|
34
|
+
await resolveS3ConfigAndInput(amplify, getUrlOptions);
|
|
35
|
+
const { inputType, objectKey } = validateStorageOperationInput(
|
|
36
|
+
input,
|
|
37
|
+
identityId,
|
|
38
|
+
);
|
|
24
39
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
40
|
+
const finalKey =
|
|
41
|
+
inputType === STORAGE_INPUT_KEY ? keyPrefix + objectKey : objectKey;
|
|
28
42
|
|
|
29
|
-
|
|
30
|
-
amplify,
|
|
31
|
-
|
|
32
|
-
);
|
|
43
|
+
if (getUrlOptions?.validateObjectExistence) {
|
|
44
|
+
await getProperties(amplify, input, StorageAction.GetUrl);
|
|
45
|
+
}
|
|
33
46
|
|
|
34
|
-
let urlExpirationInSec =
|
|
47
|
+
let urlExpirationInSec =
|
|
48
|
+
getUrlOptions?.expiresIn ?? DEFAULT_PRESIGN_EXPIRATION;
|
|
35
49
|
const awsCredExpiration = s3Config.credentials?.expiration;
|
|
36
50
|
if (awsCredExpiration) {
|
|
37
51
|
const awsCredExpirationInSec = Math.floor(
|
|
@@ -54,7 +68,7 @@ export const getUrl = async (
|
|
|
54
68
|
},
|
|
55
69
|
{
|
|
56
70
|
Bucket: bucket,
|
|
57
|
-
Key:
|
|
71
|
+
Key: finalKey,
|
|
58
72
|
},
|
|
59
73
|
),
|
|
60
74
|
expiresAt: new Date(Date.now() + urlExpirationInSec * 1000),
|