10.3.10 • Published 9 months ago

@hodfords/nestjs-storage v10.3.10

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
9 months ago

Installation 🤖

To begin using it, we first install the required dependencies.

npm install @hodfords/nestjs-storage

Configuration 🚀

To activate storage, import the StorageModule into the root AppModule and run the forRoot() static method as shown below:

Azure configuration:

import { Module } from '@nestjs/common';
import { StorageModule } from '@hodfords/nestjs-storage';

@Module({
    imports: [
        StorageModule.forRoot({
            account: {
                name: env.AZURE.ACCOUNT_NAME,
                key: env.AZURE.ACCOUNT_KEY,
                containerName: env.AZURE.CONTAINER_NAME,
                expiredIn: env.AZURE.SAS_EXPIRED_IN
            },
            disk: 'azure'
        })
    ],
})
export class AppModule {}

Aws S3 configuration:

import { Module } from '@nestjs/common';
import { StorageModule } from '@hodfords/nestjs-storage';

@Module({
    imports: [
        StorageModule.forRoot({
            account: {
                name: env.AWS.API_KEY,
                key: env.AWS.API_SECRET,
                containerName: env.AWS.BUCKET,
                expiredIn: env.AZURE.SAS_EXPIRED_IN,
                region: env.AWS.REGION
            },
            disk: 's3'
        })
    ],
})
export class AppModule {}

Driver Prerequisites:

  • Azure: npm install @azure/storage-blob
  • Aws S3: npm install @aws-sdk/client-s3 @aws-sdk/lib-storage @aws-sdk/s3-request-presigner

Usage 🚀

Inject storage instance into your service or controller and use it as shown below:

import { StorageService } from "@hodfords/nestjs-storage";

@Injectable()
export class AppService implements OnModuleInit {

    constructor(private storageService: StorageService) {
    }
}

Delete file

The delete method accepts a single filename

await this.storageService.deleteFile('path/to/file');

This method may throw an exception if the file does not exist. You can ignore this exception by using the deleteIfExists method.

await this.storageService.deleteIfExists('path/to/file');

License

This project is licensed under the MIT License

10.3.10

9 months ago

10.1.4

11 months ago

10.0.5

1 year ago

10.0.6

1 year ago

10.3.4

10 months ago

10.0.7

1 year ago

10.3.5

10 months ago

10.3.6

10 months ago

10.3.7

10 months ago

10.3.8

10 months ago

10.3.9

10 months ago

1.0.7

12 months ago

10.1.0

12 months ago

10.0.1

1 year ago

1.0.6

1 year ago

10.2.0

11 months ago

10.1.1

12 months ago

10.0.2

1 year ago

10.3.0

10 months ago

10.2.1

10 months ago

10.1.2

12 months ago

10.1.3

11 months ago

10.0.4

1 year ago

10.0.0

1 year ago

8.0.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

3 years ago