A comprehensive Python tool for uploading files to Google Cloud Storage buckets with support for single file uploads, batch directory uploads, and concurrent processing.
- Single File Upload: Upload individual files to GCS buckets
- Directory Upload: Upload entire directories with recursive file discovery
- Concurrent Processing: Multi-threaded uploads for better performance
- Progress Tracking: Visual progress bars for batch operations
- Public Access: Option to make uploaded files publicly accessible
- Error Handling: Comprehensive error handling and logging
- CLI Interface: Easy-to-use command-line interface
- Clone this repository:
git clone <repository-url>
cd gcs_uploader- Install dependencies:
pip install -r requirements.txt- Set up Google Cloud authentication:
- Create a service account in Google Cloud Console
- Download the service account key JSON file
- Set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable
Create a .env file based on .env.example:
cp .env.example .envEdit .env with your Google Cloud project details:
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/service-account-key.jsonpython main.py upload /path/to/file.txt my-bucket-namepython main.py upload /path/to/file.txt my-bucket-name --blob-name custom-name.txtpython main.py upload /path/to/file.txt my-bucket-name --publicpython main.py upload-dir /path/to/directory my-bucket-namepython main.py upload-dir /path/to/directory my-bucket-name --prefix "uploads/"python main.py upload-dir /path/to/directory my-bucket-name --max-workers 8python main.py list-bucketsfrom main import GCSUploader
# Initialize uploader
uploader = GCSUploader(project_id="your-project-id")
# Upload a single file
success = uploader.upload_file("local_file.txt", "bucket-name")
# Upload a directory
results = uploader.upload_directory("local_directory", "bucket-name")
# List buckets
buckets = uploader.list_buckets()--project-id: Google Cloud project ID--credentials: Path to service account credentials JSON file--verbose, -v: Enable verbose logging
--blob-name: Custom name for the blob in GCS--public: Make uploaded files publicly accessible--prefix: Prefix to add to blob names (directory uploads)--max-workers: Maximum number of concurrent uploads (default: 4)
The tool provides comprehensive error handling for common scenarios:
- Invalid credentials
- Bucket not found or inaccessible
- File not found
- Network errors
- Permission issues
All errors are logged with appropriate detail levels.
- Python 3.7+
- Google Cloud Storage client library
- Valid Google Cloud service account credentials
This project is open source and available under the MIT License.