@mahdi.golzar/fileuploader
v1.0.0
Published
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.
Downloads
8
Maintainers
Readme
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:
npm install aws-sdk @google-cloud/storage
Usage
- Create a FileUploader Instance
const uploader = new FileUploader();
- Configure and Upload Files
Local Storage
AWS S3 Storageuploader.useStorage('local', { path: './uploads' }); uploader.upload('./example.txt', 'example.txt');
Google Cloud Storageuploader.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');
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');