1.0.6 • Published 1 year ago

aibees-nestjs-s3 v1.0.6

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

NestJS S3 (Updated)

Table of Contents

Description

A library for NestJS to manage AWS S3 Buckets.

Installation

npm i -s aibees-nestjs-s3 aws-sdk

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

@Module({
  imports: [
    S3Module.forRoot({
      config: {
        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 'aibees-nestjs-s3';
import { AppController } from './app.controller';

@Module({
  imports: [
    S3Module.forRootAsync({
      useFactory: () => ({
        config: {
          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 'aibees-nestjs-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);
    }
  }
}

Credits

This project was forked from here. Original credits goes to @svtslv.

License

MIT

1.0.6

1 year ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago