A practical example application demonstrating how to use the clouduploader-py package for uploading files to various cloud storage backends (S3, R2, Azure Blob, GCS, and more).
- Python 3.9 or higher
- pip/pip3
- Virtual environment (recommended)
cd /home/rafeeque/Rafeeque/sample-python-apppython3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install clouduploader-pyCreate a .env file or export these variables:
export CLOUD_UPLOADER_API_KEY="your_api_key_here"
export CLOUD_UPLOADER_URL="https://api.clouduploader.io"sample-python-app/
βββ README.md # This file
βββ upload_example.py # Comprehensive example script
βββ venv/ # Virtual environment
βββ .gitignore # Git ignore rules
from cloud_uploader import CloudUploader
# Initialize the uploader
uploader = CloudUploader(
api_key="your_api_key",
base_url="https://api.clouduploader.io"
)Upload a single file to the default storage backend:
result = uploader.upload_file("path/to/file.mp4")
print(f"β
Upload complete!")
print(f" Storage path: {result.storage_path}")
print(f" Upload ID: {result.upload_id}")Track upload progress in real-time:
def progress(uploaded: int, total: int) -> None:
pct = (uploaded / total * 100) if total else 0
print(f"\rProgress: {pct:.1f}%", end="", flush=True)
result = uploader.upload_file(
"large_video.mp4",
progress_callback=progress
)
print(f"\nβ
Done β {result.storage_path}")Upload to a specific storage backend (S3, Azure, GCS, etc.):
# Upload to S3
result = uploader.upload_file("data.csv", storage="s3")
# Supported backends: r2, s3, minio, azure, gcsHandle errors gracefully:
from cloud_uploader import (
CloudUploaderError,
AuthenticationError,
UploadFailedError
)
try:
result = uploader.upload_file("file.pdf")
print(f"β
{result.storage_path}")
except AuthenticationError:
print("β Invalid API key")
except UploadFailedError as e:
print(f"β Upload failed: {e.message}")
except CloudUploaderError as e:
print(f"β Error: {e.message} (HTTP {e.status_code})")Upload all files in a directory recursively:
result = uploader.upload_folder("./assets")
print(f"β
Uploaded {result.succeeded}/{result.total_files} files")
if result.failures:
print(f"β οΈ Failed files: {len(result.failures)}")
for failure in result.failures:
print(f" - {failure.file_path}: {failure.error}")Query the status of a previous upload:
status = uploader.get_upload_status("upload_id_123")
print(f"Status: {status['status']}")
print(f"Success: {status['success']}")Download a file by its ID:
path = uploader.download_file(
file_id="file_123",
output_path="./downloads/file.jpg"
)
print(f"β
Downloaded to: {path}")uploader = CloudUploader(
api_key="your_api_key", # Required: Your API key
base_url="https://api.clouduploader.io", # Default: http://localhost:8080
timeout=30, # HTTP timeout in seconds
max_retries=3, # Retry attempts for failures
max_parallel_uploads=5, # Thread pool size for multipart
debug=False, # Enable debug logging
)# Run the example script
python upload_example.py
# With a specific file
python upload_example.py /path/to/file.mp4
# With progress tracking
python upload_example.py /path/to/file.mp4 --progress- Visit https://clouduploader.io
- Sign up or log in
- Navigate to API settings
- Generate a new API key
- Copy the key and use it in your code
- r2 - Cloudflare R2 (default)
- s3 - Amazon S3
- minio - MinIO
- azure - Azure Blob Storage
- gcs - Google Cloud Storage
Use a virtual environment:
python3 -m venv venv
source venv/bin/activate
pip install clouduploader-pyEnsure your API key is correct and valid:
export CLOUD_UPLOADER_API_KEY="your_correct_key"Check your base URL and ensure the CloudUploader service is running:
export CLOUD_UPLOADER_URL="https://api.clouduploader.io"- PyPI Package: https://pypi.org/project/clouduploader-py/
- GitHub Repository: https://github.com/CloudUploader/clouduploader-py
- Official Docs: https://docs.clouduploader.io/sdk/python
For issues, questions, or feedback:
- π§ Email: support@clouduploader.io
- π GitHub Issues: https://github.com/CloudUploader/clouduploader-py/issues
- π¬ Discussions: https://github.com/CloudUploader/clouduploader-py/discussions
MIT License - See the main package repository for details
- β
Install the package:
pip install clouduploader-py - β Set your API key in environment variables
- β
Run the example script:
python upload_example.py - β Explore the different examples in the script
- β Build your own upload logic using the SDK
Version: Based on clouduploader-py 0.1.5+ Last Updated: April 2026