UNPKG

@mahdi.golzar/fileuploader

Version:

FileUploader is a versatile tool designed for uploading files to various storage systems. It supports local storage, AWS S3, and Google Cloud Storage, with easy-to-use methods for file uploading.

43 lines (41 loc) 1.43 kB
# FileUploader FileUploader is a versatile tool designed for uploading files to various storage systems. It supports local storage, AWS S3, and Google Cloud Storage, with easy-to-use methods for file uploading. ## Features - Multiple Storage Types: Supports local file storage, AWS S3, and Google Cloud Storage. - Dynamic Configuration: Easily switch between different storage systems with dynamic configuration. - Simple Upload Method: Upload files using a unified method. ## Installation Install the required dependencies: ```bash npm install aws-sdk @google-cloud/storage ``` ## Usage 1. Create a FileUploader Instance ```javascript const uploader = new FileUploader(); ``` 2. Configure and Upload Files Local Storage ```javascript uploader.useStorage('local', { path: './uploads' }); uploader.upload('./example.txt', 'example.txt'); ``` AWS S3 Storage ```javascript uploader.useStorage('s3', { accessKeyId: 'YOUR_AWS_ACCESS_KEY_ID', secretAccessKey: 'YOUR_AWS_SECRET_ACCESS_KEY', region: 'YOUR_AWS_REGION', bucketName: 'YOUR_S3_BUCKET_NAME' }); uploader.upload('./example.txt', 'example.txt'); ``` Google Cloud Storage ```javascript uploader.useStorage('gcs', { projectId: 'YOUR_GCS_PROJECT_ID', keyFilename: 'path/to/your-service-account-key.json', bucketName: 'YOUR_GCS_BUCKET_NAME' }); uploader.upload('./example.txt', 'example.txt'); ```