Skip to content

BeerMoneyDev/nest-file-manager

Repository files navigation

nest-file-manager


An abstraction layer to simplify cloud file management in NestJS.

NPM Version Package License NPM Downloads

Features

  • A unified file management service to manager files on disk, Azure, or AWS with the same code and service interface.

How To Use

Install

npm install --save nest-file-manager
npm install --save aws-sdk # if using AWS
npm install --save @azure/storage-blob # if using Azure

Basic Usage

// app.module.ts
import { Module } from '@nestjs/common';
import { FileManagerModule } from 'nest-file-manager';

@Module({
  imports: [
    S3ManagerModule,
    FileManagerModule.registerAsync({
      aws: { // optional, only needed if you use this provider
        /**
         * Use the useValue method
         */
        useValue: {
          accessKeyId: "AKIAU77LDZ6OMENV354Z",
          secretAccessKey: "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",
          bucketRegion: "us-east-1",
          signatureVersion: "v4"
        },

        /**
         * OR use the factory method
         */
        useFactory: (configService: ConfigService) => {
          return configService.get('AWS_SETTINGS');
        },
        inject: [ConfigService],
        imports: [ConfigModule]
      },
      azure: { // optional, only needed if you use this provider
        useValue: {
          accountName: "myAccount",
          accountKey: "pt7wl+zzVUTFyIokJ8zIJErb/Le3hXLJ+bFmVCcjJop5BlE+ASt4GNYp2m1lgKoCX3JkFqIzhtydnV73dr+lCg=="
        }
      },
      disk: { // optional, only needed if you use this provider
        useValue: {
          rootDirectory: "E:\\public-uploads",
          rootUrl: "http://localhost"
        }
      }
    }),
  ],
  providers: [],
  exports: [],
})
export class AppModule {}
import { FileService, InjectFileService } from "nest-file-manager";

export class MyService {
  constructor(
    @InjectFileService("AWS") // or "Azure" or "Disk"
    readonly fileService: FileService
  ) {}

  async handleFileUpload() {
    await this.fileService.writeFile({
      filePath: "E:\\temp\\myfile.txt",
      destFileName: "myuploadedfile.txt",
      bucketName: "myfiles"
    });
  }
}

Stay In Touch

License

nest-file-manager is MIT licensed.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published