0.0.11 • Published 1 year ago

@prachyot/nestjs-s3 v0.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

S3 Module

A NestJS module to provide a S3 client and a S3 service for your application.

Implementation purpose

  1. Reduce project setup time
  2. Reduce project onboarding time
  3. Help lean your base project

Installation

yarn add @prachyot/nestjs-s3

Usage

Add these new variable to your .env file

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

Import the module in your AppModule

import { S3Module } from '@prachyot/nestjs-s3';
...

@Module({
  imports: [
    S3Module
    ...
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

You can change the default configuration by passing an object to the forRoot method

import { S3Module } from '@prachyot/nestjs-s3';
...

@Module({
  imports: [
    S3Module.forRoot({
      envFilePath: '.env.local' // Change the path to your env file
    })
    ...
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Or you can use forRootAsync method to pass a factory function

import { S3Module } from '@prachyot/nestjs-s3';
...

@Module({
  imports: [
    S3Module.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          envFilePath: configService.get('ENV_FILE_PATH'),
        }
      }
    })
    ...
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Service method specification

// Method: s3
// Description: Returns an instance of the S3 client

this.s3Service.s3();
/*
 * Method: uploadFile
 * Description: Uploads a file to S3
 *
 * @Params:
 * bucketName: string
 * dir: string
 * fileName: string
 * cacheAge: number (optional) (default: 31536000) (1 year)
 */

await this.uploadFile('my-bucket', 'src/assets', 'my-file.png');
0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago