nestjs-aws-s3
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

NestJS S3

NPM Version Package License

Table of Contents

Description

Integrates @aws-sdk/client-s3 with Nest.JS

Installation

yarn add nestjs-aws-s3 @aws-sdk/client-s3

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-aws-s3';
import { AppController } from './app.controller';

@Module({
  imports: [
    S3Module.forRoot({
      accessKeyId: 'minio',
      secretAccessKey: 'password',
      endpoint: 'http://127.0.0.1:9000'
    }),
  ],
  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: {
          accessKeyId: 'minio',
          secretAccessKey: 'password',
          endpoint: 'http://localhost:9000'
        },
      }),
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

InjectS3(connection?)

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

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

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

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

License

MIT

Package Sidebar

Install

npm i nestjs-aws-s3

Weekly Downloads

143

Version

2.0.1

License

MIT

Unpacked Size

14.3 kB

Total Files

20

Last publish

Collaborators

  • wisekaa03