1 | {"version":3,"file":"index.mjs","sources":["../../../../../../src/providers/s3/apis/uploadData/index.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createUploadTask } from '../../utils';\nimport { assertValidationError } from '../../../../errors/utils/assertValidationError';\nimport { StorageValidationErrorCode } from '../../../../errors/types/validation';\nimport { DEFAULT_PART_SIZE, MAX_OBJECT_SIZE } from '../../utils/constants';\nimport { byteLength } from './byteLength';\nimport { putObjectJob } from './putObjectJob';\nimport { getMultipartUploadHandlers } from './multipart';\n/**\n * Upload data to specified S3 object. By default, it uses single PUT operation to upload if the data is less than 5MB.\n * Otherwise, it uses multipart upload to upload the data. If the data length is unknown, it uses multipart upload.\n *\n * Limitations:\n * * Maximum object size is 5TB.\n * * Maximum object size if the size cannot be determined before upload is 50GB.\n *\n * @param input - The UploadDataInput object.\n * @returns A cancelable and resumable task exposing result promise from `result`\n * \tproperty.\n * @throws service: {@link S3Exception} - thrown when checking for existence of the object\n * @throws validation: {@link StorageValidationErrorCode } - Validation errors.\n *\n * @example\n * ```ts\n * // Upload a file to s3 bucket\n * await uploadData({ key, data: file, options: {\n * onProgress, // Optional progress callback.\n * } }).result;\n * ```\n * @example\n * ```ts\n * // Cancel a task\n * const uploadTask = uploadData({ key, data: file });\n * //...\n * uploadTask.cancel();\n * try {\n * await uploadTask.result;\n * } catch (error) {\n * if(isCancelError(error)) {\n * // Handle error thrown by task cancelation.\n * }\n * }\n *```\n *\n * @example\n * ```ts\n * // Pause and resume a task\n * const uploadTask = uploadData({ key, data: file });\n * //...\n * uploadTask.pause();\n * //...\n * uploadTask.resume();\n * //...\n * await uploadTask.result;\n * ```\n */\nexport const uploadData = (input) => {\n const { data } = input;\n const dataByteLength = byteLength(data);\n assertValidationError(dataByteLength === undefined || dataByteLength <= MAX_OBJECT_SIZE, StorageValidationErrorCode.ObjectIsTooLarge);\n if (dataByteLength && dataByteLength <= DEFAULT_PART_SIZE) {\n const abortController = new AbortController();\n return createUploadTask({\n isMultipartUpload: false,\n job: putObjectJob(input, abortController.signal, dataByteLength),\n onCancel: (message) => {\n abortController.abort(message);\n },\n });\n }\n else {\n const { multipartUploadJob, onPause, onResume, onCancel } = getMultipartUploadHandlers(input, dataByteLength);\n return createUploadTask({\n isMultipartUpload: true,\n job: multipartUploadJob,\n onCancel: (message) => {\n onCancel(message);\n },\n onPause,\n onResume,\n });\n }\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,UAAU,GAAG,CAAC,KAAK,KAAK;AACrC,IAAI,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC3B,IAAI,MAAM,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;AAC5C,IAAI,qBAAqB,CAAC,cAAc,KAAK,SAAS,IAAI,cAAc,IAAI,eAAe,EAAE,0BAA0B,CAAC,gBAAgB,CAAC,CAAC;AAC1I,IAAI,IAAI,cAAc,IAAI,cAAc,IAAI,iBAAiB,EAAE;AAC/D,QAAQ,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AACtD,QAAQ,OAAO,gBAAgB,CAAC;AAChC,YAAY,iBAAiB,EAAE,KAAK;AACpC,YAAY,GAAG,EAAE,YAAY,CAAC,KAAK,EAAE,eAAe,CAAC,MAAM,EAAE,cAAc,CAAC;AAC5E,YAAY,QAAQ,EAAE,CAAC,OAAO,KAAK;AACnC,gBAAgB,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC/C,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK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