1 | import { Amplify } from '@aws-amplify/core';
|
2 | import { StorageAction } from '@aws-amplify/core/internals/utils';
|
3 | import { calculateContentMd5 } from '../../utils/md5.mjs';
|
4 | import { resolveS3ConfigAndInput } from '../../utils/resolveS3ConfigAndInput.mjs';
|
5 | import '../../../../errors/types/validation.mjs';
|
6 | import '../../../../utils/logger.mjs';
|
7 | import '../../utils/client/base.mjs';
|
8 | import '../../utils/client/getObject.mjs';
|
9 | import '../../utils/client/listObjectsV2.mjs';
|
10 | import { putObject } from '../../utils/client/putObject.mjs';
|
11 | import '../../utils/client/createMultipartUpload.mjs';
|
12 | import '../../utils/client/uploadPart.mjs';
|
13 | import '../../utils/client/completeMultipartUpload.mjs';
|
14 | import '../../utils/client/listParts.mjs';
|
15 | import '../../utils/client/abortMultipartUpload.mjs';
|
16 | import '../../utils/client/copyObject.mjs';
|
17 | import '../../utils/client/headObject.mjs';
|
18 | import '../../utils/client/deleteObject.mjs';
|
19 | import { getStorageUserAgentValue } from '../../utils/userAgent.mjs';
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | const putObjectJob = ({ options: uploadDataOptions, key, data }, abortSignal, totalLength) => async () => {
|
29 | const { bucket, keyPrefix, s3Config, isObjectLockEnabled } = await resolveS3ConfigAndInput(Amplify, uploadDataOptions);
|
30 | const finalKey = keyPrefix + key;
|
31 | const { contentDisposition, contentEncoding, contentType = 'application/octet-stream', metadata, onProgress, } = uploadDataOptions ?? {};
|
32 | const { ETag: eTag, VersionId: versionId } = await putObject({
|
33 | ...s3Config,
|
34 | abortSignal,
|
35 | onUploadProgress: onProgress,
|
36 | userAgentValue: getStorageUserAgentValue(StorageAction.UploadData),
|
37 | }, {
|
38 | Bucket: bucket,
|
39 | Key: finalKey,
|
40 | Body: data,
|
41 | ContentType: contentType,
|
42 | ContentDisposition: contentDisposition,
|
43 | ContentEncoding: contentEncoding,
|
44 | Metadata: metadata,
|
45 | ContentMD5: isObjectLockEnabled
|
46 | ? await calculateContentMd5(data)
|
47 | : undefined,
|
48 | });
|
49 | return {
|
50 | key,
|
51 | eTag,
|
52 | versionId,
|
53 | contentType,
|
54 | metadata,
|
55 | size: totalLength,
|
56 | };
|
57 | };
|
58 |
|
59 | export { putObjectJob };
|
60 |
|