Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svtslv/nestjs-s3
S3 module for Nest
https://github.com/svtslv/nestjs-s3
aws minio nest nestjs s3 storage
Last synced: 4 days ago
JSON representation
S3 module for Nest
- Host: GitHub
- URL: https://github.com/svtslv/nestjs-s3
- Owner: svtslv
- Created: 2020-02-28T18:48:43.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-28T03:15:17.000Z (about 1 year ago)
- Last Synced: 2024-04-25T14:02:32.799Z (7 months ago)
- Topics: aws, minio, nest, nestjs, s3, storage
- Language: TypeScript
- Size: 702 KB
- Stars: 72
- Watchers: 3
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NestJS S3
## Table of Contents
- [Description](#description)
- [Installation](#installation)
- [Examples](#examples)
- [License](#license)## Description
Integrates S3 with Nest## Installation
```bash
npm install nestjs-s3 @aws-sdk/client-s3
```You can also use the interactive CLI
```sh
npx nestjs-modules
```## Examples
```bash
docker run \
-p 9000:9000 \
-e MINIO_ACCESS_KEY=minio \
-e MINIO_SECRET_KEY=password \
minio/minio server /data
```### S3Module.forRoot(options, connection?)
```ts
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',
},
// region: 'us-east-1',
endpoint: 'http://127.0.0.1:9000',
forcePathStyle: true,
signatureVersion: 'v4',
},
}),
],
controllers: [AppController],
})
export class AppModule {}
```### S3Module.forRootAsync(options, connection?)
```ts
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',
},
// region: 'us-east-1',
endpoint: 'http://localhost:9000',
forcePathStyle: true,
signatureVersion: 'v4',
},
}),
}),
],
controllers: [AppController],
})
export class AppModule {}
```### InjectS3(connection?)
```ts
import { Controller, Get, } from '@nestjs/common';
import { InjectS3, S3 } from 'nestjs-s3';@Controller()
export class AppController {
constructor(
@InjectS3() private readonly s3: S3,
) {}@Get()
async listBuckets() {
try {
await this.s3.createBucket({ Bucket: 'bucket' });
} catch (e) {}try {
// this.s3.send(new ListBucketsCommand({}))
const list = await this.s3.listBuckets({});
return list.Buckets;
} catch (e) {
console.log(e);
}
}
}
```## License
MIT