An open API service indexing awesome lists of open source software.

https://github.com/muhammadzadeh/nestorage

NestJS Storage module, work with famous object storage like S3, R2, Azure, Google Cloud
https://github.com/muhammadzadeh/nestorage

azure-storage cloudflare-r2 gcloud localstorage minio r2 s3 s3-storage

Last synced: 12 months ago
JSON representation

NestJS Storage module, work with famous object storage like S3, R2, Azure, Google Cloud

Awesome Lists containing this project

README

          

Nestorage Logo

NestJS Storage module, work with famous object storage like S3, R2, Azure, Google Cloud

## Installation

```bash
npm i --save @muhammadzadeh/nestorage
```

## How To

- select your preferred provider and provide its configs
- [local](#local-storage-example)
- [s3](#s3-storage-example)
- [r2](#r2-storage-example)
- [azure](#azure-storage-example)
- [gcs](#google-cloud-storage-example)
- inject StorageService
- [StorageService](#storageservice)

### Local Storage Example

```typescript
// app.module.ts

import { Module } from '@nestjs/common';

import { StorageModule } from '@muhammadzadeh/nestorage';

@Module({
imports: [
StorageModule.forRoot({
provider: 'local',
options: {
root: 'ROOT_DIR',
},
}),
],
})
export class AppModule {}
```

### S3 Storage Example

```typescript
// app.module.ts

import { Module } from '@nestjs/common';

import { StorageModule } from '@muhammadzadeh/nestorage';

@Module({
imports: [
StorageModule.forRoot({
provider: 's3',
options: {
accessKeyId: 'ACCESS_KEY_ID',
secretAccessKey: 'SECRET_ACCESS_KEY',
endpoint: 'S3_ENDPOINT',
region: 'auto',
},
}),
],
})
export class AppModule {}
```

### R2 Storage Example

```typescript
// app.module.ts

import { Module } from '@nestjs/common';

import { StorageModule } from '@muhammadzadeh/nestorage';

@Module({
imports: [
StorageModule.forRoot({
provider: 'r2',
options: {
accessKeyId: 'ACCESS_KEY_ID',
secretAccessKey: 'SECRET_ACCESS_KEY',
endpoint: 'CLOUDFLARE_R2_EXAMPLE',
region: 'auto',
},
}),
],
})
export class AppModule {}
```

### Azure Storage Example

```typescript
// app.module.ts

import { Module } from '@nestjs/common';

import { StorageModule } from '@muhammadzadeh/nestorage';

@Module({
imports: [
StorageModule.forRoot({
provider: 'azure',
options: {
connectionString: 'CONNECTION_STRING ',
},
}),
],
})
export class AppModule {}
```

### Google Cloud Storage Example

```typescript
// app.module.ts

import { Module } from '@nestjs/common';

import { StorageModule } from '@muhammadzadeh/nestorage';

@Module({
imports: [
StorageModule.forRoot({
provider: 'gcs',
options: {
keyFilename: 'GOOGLE_KEY_FILE_NAME',
},
}),
],
})
export class AppModule {}
```

### StorageService

```typescript
import { Injectable, StreamableFile } from '@nestjs/common';
import { StorageService } from '@muhammadzadeh/nestorage';

@Injectable()
export class MyClass {
constructor(private readonly storage: StorageService) {}

async uploadFile(file: Express.Multer.File) {
await this.storage.putObject(
'bucket',
'path/to/sub',
'my-file1.png',
file.buffer,
);
}

async DownloadFile() {
const buffer = await this.storage.getObject(
'bucket',
'path/to/sub',
'my-file.png',
);
return new StreamableFile(buffer, {
type: 'png',
length: buffer.length,
disposition: `attachment; filename="my-file.png"`,
});
}
}
```

## Todo

- [ ] Add tests
- [ ] Manage Buckets(create, delete, list)
- [ ] Delete Object
- [ ] Copy Object
- [ ] Share Object

## Support

nestorage is an MIT-licensed open source project. If this library is helpful, please click star to support it.

## License

nestorage is MIT licensed.