nest-background-file-upload
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Common Background File Upload Package

Overview

The Common Background File Upload Package provides functionality to upload multiple files to various storage services seamlessly in the background. This ensures efficient file handling and improves application performance by offloading the upload process.

🚨 Redis is mandatory for background task management. Without Redis, the package will not function as expected. It ensures smooth processing, queuing, and tracking of file uploads.

Supported storage platforms include:

  • Local Server
  • Google Cloud Platform (GCP)
  • Amazon Web Services (AWS) (Currently Under Maintenance)
  • Azure (Currently Under Maintenance)

This package also supports optional file compression (Under Maintenance) by specifying a dynamic quality ratio based on file size.


Installation

To install the package, use the following command:

npm install nest-background-file-upload

Ensure that you have the necessary dependencies installed based on your storage provider. Redis is a required dependency for background task management. You must have a Redis server running to use this package.


Configuration and Usage

To enable background file uploading, register the FileUploaderModule in your application module with the desired storage configuration.

🚀 Redis Configuration (Required)

Redis is required to manage background file uploads efficiently. Below is the standard configuration:

const redisConfiguration = {
  host: 'localhost', // Redis server host
  port: 6379, // Redis server port
  password: 'your-redis-password', // Optional Redis password
  db: 0, // Redis database index
}

Local Server Storage

import { FileUploaderModule } from 'nest-background-file-upload';

@Module({
  imports: [
    FileUploaderModule.register({
      redis: redisConfiguration,
      storageType: 'local',
      localPath: 'path-to-upload-folder',
    }),
  ],
})
export class AppModule {}

Google Cloud Platform (GCP) Storage

import { FileUploaderModule } from 'nest-background-file-upload';

@Module({
  imports: [
    FileUploaderModule.register({
      redis: redisConfiguration,
      storageType: 'gcp',
      gcp: {
        bucketName: 'cloud-bucket-name',
        credentials: 'gcp-credentials-json-object',
      },
    }),
  ],
})
export class AppModule {}

Amazon Web Services (AWS) S3 Storage (Under Maintenance)

import { FileUploaderModule } from 'nest-background-file-upload';

@Module({
  imports: [
    FileUploaderModule.register({
      redis: redisConfiguration,
      storageType: 's3',
      s3: {
        accessKeyId: 'your-access-key-id',
        secretAccessKey: 'your-secret-access-key',
        region: 'your-region',
        bucket: 'your-bucket-name',
      },
    }),
  ],
})
export class AppModule {}

Microsoft Azure Blob Storage (Under Maintenance)

import { FileUploaderModule } from 'nest-background-file-upload';

@Module({
  imports: [
    FileUploaderModule.register({
      redis: redisConfiguration,
      storageType: 'azure',
      azure: {
        connectionString: 'azure-connection-string',
        containerName: 'storage-container-name',
      },
    }),
  ],
})
export class AppModule {}

Dynamic File Compression (Under Maintenance)

You can enable dynamic file compression by specifying quality ratios based on file size. This helps optimize storage while maintaining file quality.

import { FileUploaderModule } from 'nest-background-file-upload';

@Module({
  imports: [
    FileUploaderModule.register({
      redis: redisConfiguration,
      compressionNeeded: true,
      compressionRatio: [
        { fileSize: [0, 500000], ratio: 90 }, // 90% quality for files ≤ 500KB
        { fileSize: [500001, 2000000], ratio: 70 }, // 70% quality for files between 500KB - 2MB
        { fileSize: [2000001, Infinity], ratio: 50 }, // 50% quality for files > 2MB
      ],
    }),
  ],
})
export class AppModule {}

Features

  • ✅ Supports multiple storage providers
  • Asynchronous background uploads for performance optimization
  • Redis is mandatory for background task handling and tracking
  • Modular and scalable integration for NestJS applications
  • Easy configuration for different cloud platforms
  • Handles multiple file uploads efficiently
  • Supports conditional file compression (Under Maintenance) based on file size ranges
  • Tracks upload progress using Redis for better monitoring

Roadmap

  • ✅ Support for Local and GCP storage
  • 🔧 AWS and Azure support (Currently under maintenance)
  • 🚀 Future enhancements including file processing, metadata handling, and enhanced error tracking

Package Sidebar

Install

npm i nest-background-file-upload

Weekly Downloads

4

Version

1.0.1

License

none

Unpacked Size

280 kB

Total Files

21

Last publish

Collaborators

  • abhay-dalsaniya