2.0.1 • Published 11 months ago

nestjs-s3 v2.0.1

Weekly downloads
3,809
License
MIT
Repository
github
Last release
11 months ago

NestJS S3

Table of Contents

Description

Integrates S3 with Nest

Installation

npm install nestjs-s3 @aws-sdk/client-s3

You can also use the interactive CLI

npx nestjs-modules

Examples

docker run \
-p 9000:9000 \
-e MINIO_ACCESS_KEY=minio \
-e MINIO_SECRET_KEY=password \
minio/minio server /data

S3Module.forRoot(options, connection?)

import { Module } from '@nestjs/common';
import { S3Module } from 'nestjs-s3';
import { AppController } from './app.controller';

@Module({
  imports: [
    S3Module.forRoot({
      config: {
        credentials: {
          accessKeyId: 'minio',
          secretAccessKey: 'password',
        },
        endpoint: 'http://127.0.0.1:9000',
        s3ForcePathStyle: true,
        signatureVersion: 'v4',
      },
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

S3Module.forRootAsync(options, connection?)

import { Module } from '@nestjs/common';
import { S3Module } from 'nestjs-s3';
import { AppController } from './app.controller';

@Module({
  imports: [
    S3Module.forRootAsync({
      useFactory: () => ({
        config: {
          credentials: {
            accessKeyId: 'minio',
            secretAccessKey: 'password',
          },
          endpoint: 'http://localhost:9000',
          s3ForcePathStyle: true,
          signatureVersion: 'v4',
        },
      }),
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

InjectS3(connection?)

import { Controller, Get, } from '@nestjs/common';
import { InjectS3, S3 } from 'nestjs-s3';

@Controller()
export class AppController {
  constructor(
    @InjectS3() private readonly s3: S3,
  ) {}

  @Get()
  async getHello() {
    try {
      await this.s3.createBucket({ Bucket: 'bucket' });
    } catch (e) {}

    try {
      const list = await this.s3.listBuckets({});
      return list.Buckets;
    } catch (e) {
      console.log(e);
    }
  }
}

License

MIT

2.1.0-next.1

11 months ago

2.0.0-next.1

12 months ago

2.0.1

12 months ago

2.0.0

12 months ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago