0.0.9 • Published 3 months ago

nest-aws-s3 v0.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

nest-aws-s3

This is a simple, clean, and easy-to-use NestJS module for Amazon S3 integration, leveraging the latest AWS SDK v3. It's designed for quick integration and minimal setup, making your development process smoother.

Features

  • Easy integration with AWS S3 for NestJS applications.
  • Clean and optimized codebase.
  • Wide range of S3 functionalities.

Installation

npm install nest-aws-s3

Configuration

In your NestJS module:

import { S3Module } from 'nest-aws-s3';

@Module({
  imports: [
    S3Module.forRoot({
      defaultServiceOptions: {
        region: 'us-east-1',
        credentials: {
          accessKeyId: 'your-access-key',
          secretAccessKey: 'your-secret-key',
        },
      },
    }),
    // ... other imports
  ],
})
export class AppModule {}

Usage

Upload a File

@Injectable()
export class YourService {
  constructor(private readonly s3Service: S3Service) {}

  async uploadFile(file: Buffer, bucket: string, key: string) {
    return this.s3Service.uploadFile(bucket, key, file);
  }
}

Retrieve a File

export class YourService {
    constructor(private readonly s3Service: S3Service) {
    }

    async getFile(bucket: string, key: string) {
        return this.s3Service.getFile(bucket, key);
    }
}

Delete a File

export class YourService {
    constructor(private readonly s3Service: S3Service) {
    }

    async deleteFile(bucket: string, key: string) {
        return this.s3Service.deleteFile(bucket, key);
    }
}

Supported Methods

The nest-aws-s3 package includes a variety of methods for interacting with AWS S3, including:

  • uploadFile(bucket: string, key: string, body: Buffer): Upload a file to a specified bucket.
  • getFile(bucket: string, key: string): Retrieve a file from a specified bucket.
  • deleteFile(bucket: string, key: string): Delete a file from a specified bucket.
  • deleteFiles(bucket: string, keys: string[]): Delete multiple files from a specified bucket.
  • listFiles(bucket: string): List all files in a specified bucket.
  • copyFile(sourceBucket: string, sourceKey: string, destBucket: string, destKey: string): Copy a file within or across buckets.
  • createBucket(bucket: string): Create a new S3 bucket.
  • deleteBucket(bucket: string): Delete an S3 bucket.
  • getSignedUrl(bucket: string, key: string, expires: number): Generate a signed URL for a file.
  • moveFile(sourceBucket: string, sourceKey: string, destBucket: string, destKey: string): Move a file within or across buckets.

These methods provide comprehensive coverage of common S3 operations, simplifying the process of integrating AWS S3 into your NestJS applications.

Helper Classes and Their Methods

Our nest-aws-s3 module enhances S3 operations with several helper classes:

UploadFileChain

  • withUrl(): Generates a URL for the uploaded file.
  • withPublicAccess(allowPublicAccess: boolean): Sets the file's public access.

GetFileChain

  • withMetaData(): Retrieves metadata of the file.
  • withDownloadLink(): Generates a download link for the file.

ListFilesChain

  • listFilesWithFilter(prefix?: string, suffix?: string): Filters files with specific prefix and/or suffix.
  • getBucketSize(): Calculates the total size of all files in the bucket.

Contributing

Feel free to contribute, report issues, and request features!

License

This project is licensed under the ISC License.

0.0.9

3 months ago

0.0.8

3 months ago

0.0.7

3 months ago

0.0.6

3 months ago

0.0.5

3 months ago

0.0.4

3 months ago

0.0.3

3 months ago

0.0.2

3 months ago

0.0.1

3 months ago