UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

67 lines (60 loc) 2.16 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { AmplifyContext, getGlobalContext, isAmplifyContext, } from '@aws-amplify/core'; import { readFile } from '../../client/utils/readFile'; import { toBase64 } from '../../client/utils/toBase64'; import { UploadDataInput } from '../types/inputs'; import { UploadDataOutput } from '../types/outputs'; import { uploadData as uploadDataInternal } from '../../providers/s3/apis/internal/uploadData'; /** * @internal */ export function uploadData( ctx: AmplifyContext, input: UploadDataInput, ): UploadDataOutput; /** * @internal */ export function uploadData(input: UploadDataInput): UploadDataOutput; export function uploadData( ctxOrInput: AmplifyContext | UploadDataInput, maybeInput?: UploadDataInput, ): UploadDataOutput { // Resolve the optional leading context. The global context is resolved at // CALL time (never cached) so single-arg callers follow live configuration. const [ctx, input]: [AmplifyContext, UploadDataInput] = isAmplifyContext( ctxOrInput, ) ? [ctxOrInput, maybeInput as UploadDataInput] : [getGlobalContext(), ctxOrInput]; const { data, path, options } = input; return uploadDataInternal( { amplify: ctx, readFile, toBase64 }, { path, data, options: { useAccelerateEndpoint: options?.useAccelerateEndpoint, bucket: options?.bucket, onProgress: options?.onProgress, contentDisposition: options?.contentDisposition, contentEncoding: options?.contentEncoding, contentType: options?.contentType, metadata: options?.metadata, preventOverwrite: options?.preventOverwrite, expectedBucketOwner: options?.expectedBucketOwner, checksumAlgorithm: options?.checksumAlgorithm, // Advanced options locationCredentialsProvider: options?.locationCredentialsProvider, customEndpoint: options?.customEndpoint, }, }, // Type casting is necessary because `uploadDataInternal` supports both Gen1 and Gen2 signatures, but here // given in input can only be Gen2 signature, the return can only ben Gen2 signature. ) as UploadDataOutput; }