UNPKG

2.38 kBJavaScriptView Raw
1import { Amplify } from '@aws-amplify/core';
2import { StorageAction } from '@aws-amplify/core/internals/utils';
3import { calculateContentMd5 } from '../../utils/md5.mjs';
4import { resolveS3ConfigAndInput } from '../../utils/resolveS3ConfigAndInput.mjs';
5import '../../../../errors/types/validation.mjs';
6import '../../../../utils/logger.mjs';
7import '../../utils/client/base.mjs';
8import '../../utils/client/getObject.mjs';
9import '../../utils/client/listObjectsV2.mjs';
10import { putObject } from '../../utils/client/putObject.mjs';
11import '../../utils/client/createMultipartUpload.mjs';
12import '../../utils/client/uploadPart.mjs';
13import '../../utils/client/completeMultipartUpload.mjs';
14import '../../utils/client/listParts.mjs';
15import '../../utils/client/abortMultipartUpload.mjs';
16import '../../utils/client/copyObject.mjs';
17import '../../utils/client/headObject.mjs';
18import '../../utils/client/deleteObject.mjs';
19import { getStorageUserAgentValue } from '../../utils/userAgent.mjs';
20
21// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
23/**
24 * Get a function the returns a promise to call putObject API to S3.
25 *
26 * @internal
27 */
28const 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
59export { putObjectJob };
60//# sourceMappingURL=putObjectJob.mjs.map