@uploadx/s3
Version:
Uploadx S3 module
94 lines (93 loc) • 2.9 kB
TypeScript
import { ObjectCannedACL, Part, S3Client, S3ClientConfig } from '@aws-sdk/client-s3';
import { BaseStorage, BaseStorageOptions, File, FileInit, FilePart, FileQuery, HttpError, IncomingMessage, LocalMetaStorageOptions, MetaStorage } from '@uploadx/core';
import { AWSError } from './aws-error';
import { S3MetaStorageOptions } from './s3-meta-storage';
export declare class S3File extends File {
Parts?: Part[];
UploadId?: string;
uri?: string;
partsUrls?: string[];
partSize?: number;
}
export type S3StorageOptions = BaseStorageOptions<S3File> & S3ClientConfig & {
/**
* S3 bucket
* @defaultValue 'node-uploadx'
*/
bucket?: string;
/**
* Specifying access rules for uploaded files
*/
acl?: ObjectCannedACL;
/**
* Force compatible client upload directly to S3 storage
*/
clientDirectUpload?: boolean;
/**
* The parts size that the client should use for presigned multipart unloading
* @defaultValue '16MB'
*/
partSize?: number | string;
/**
* Configure metafiles storage
* @example
* Using local metafiles
* ```ts
* const storage = new S3Storage({
* bucket: 'uploads',
* region: 'eu-west-3',
* metaStorageConfig: { directory: '/tmp/upload-metafiles' }
* })
* ```
* Using a separate bucket for metafiles
* ```ts
* const storage = new S3Storage({
* bucket: 'uploads',
* region: 'eu-west-3',
* metaStorageConfig: { bucket: 'upload-metafiles' }
* })
* ```
*/
metaStorageConfig?: LocalMetaStorageOptions | S3MetaStorageOptions;
/**
* @deprecated Use standard auth providers
*/
keyFile?: string;
};
/**
* S3 storage based backend.
* @example
* ```ts
* const storage = new S3Storage({
* bucket: <YOUR_BUCKET>,
* endpoint: <YOUR_ENDPOINT>,
* region: <YOUR_REGION>,
* credentials: {
* accessKeyId: <YOUR_ACCESS_KEY_ID>,
* secretAccessKey: <YOUR_SECRET_ACCESS_KEY>
* },
* metaStorageConfig: { directory: '/tmp/upload-metafiles' }
* });
* ```
*/
export declare class S3Storage extends BaseStorage<S3File> {
config: S3StorageOptions;
bucket: string;
client: S3Client;
meta: MetaStorage<S3File>;
checksumTypes: string[];
private readonly _partSize;
constructor(config?: S3StorageOptions);
normalizeError(error: AWSError): HttpError;
create(req: IncomingMessage, config: FileInit): Promise<S3File>;
write(part: FilePart | FileQuery): Promise<S3File>;
delete({ id }: FileQuery): Promise<S3File[]>;
update({ id }: FileQuery, metadata: Partial<S3File>): Promise<S3File>;
accessCheck(maxWaitTime?: number): Promise<any>;
private buildPresigned;
private getPartsPresignedUrls;
private _onComplete;
private _getParts;
private _completeMultipartUpload;
private _abortMultipartUpload;
}