cloud-storage-factory
v1.1.2
Published
[](https://www.npmjs.com/package/cloud-storage-factory) [](https://opensource.org/licenses/MIT) [. This SDK simplifies cloud storage operations while maintaining type safety and flexibility.
Table of Contents
Features
- Unified API: Consistent interface across all supported cloud providers
- File Operations: Upload, download, and delete files with ease
- Pre-signed URLs: Generate secure, time-limited upload URLs
- Type Safety: Full TypeScript support with comprehensive type definitions
- Factory Pattern: Easy provider switching and configuration
- Zero Dependencies: Lightweight and efficient
- Async/Await: Modern Promise-based API
- Extensible: Easy to add support for new cloud providers
Installation
# Using npm
npm install cloud-storage-factory
# Using yarn
yarn add cloud-storage-factory
# Using pnpm
pnpm add cloud-storage-factoryUsage
1. Import the Factory
import { StorageFactory } from 'cloud-storage-factory';2. Initialize a Provider
AWS S3
const storage = StorageFactory('aws', {
region: 'us-east-1',
bucket: 'your-bucket-name',
credentials: {
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key',
},
});Azure Blob Storage
const storage = StorageFactory('azure', {
accountName: 'your-account-name',
accountKey: 'your-account-key',
containerName: 'your-container-name',
});Google Cloud Storage
const storage = StorageFactory('gcp', {
bucket: 'your-gcp-bucket-name',
keyFilename: 'path/to/service-account.json',
});Cloudflare R2
const storage = StorageFactory('r2', {
accountId: 'your-account-id',
accessKeyId: 'your-access-key-id',
secretAccessKey: 'your-secret-access-key',
bucket: 'your-bucket-name',
});3. Use the Storage Methods
// Upload a file
await storage.uploadFile('local/path.txt', 'remote/path.txt');
// Generate a pre-signed upload URL (valid for 1 hour)
const url = await storage.uploadPreSignedUrl('remote/upload.txt');
// Download a file
await storage.downloadFile('remote/path.txt', 'local/downloaded.txt');
// Delete a file
await storage.deleteFile('remote/path.txt');Supported Cloud Providers
| Provider | Required Config | | -------- | ----------------------------------------------- | | AWS | region, bucket, accessKeyId, secretAccessKey | | Azure | accountName, accountKey, containerName | | GCP | bucket, keyFilename | | R2 | accountId, accessKeyId, secretAccessKey, bucket |
Troubleshooting
Common Issues
Authentication Errors
- Verify your credentials are correct
- Check if your credentials have expired
- Ensure proper permissions are set
Network Issues
- Check your internet connection
- Verify firewall settings
- Ensure proper endpoint configuration
File Operations
- Verify file paths are correct
- Check file permissions
- Ensure sufficient storage space
Contributing
We welcome contributions! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone the repository
git clone https://github.com/Anshuljain30/cloud-storage-factory.git
# Install dependencies
npm install
# Run tests
npm test
# Build the project
npm run buildLicense
MIT License © 2025
Made with ❤️ by Anshul Jain
