Created
February 3, 2025 20:18
-
-
Save UltiRequiem/6eedf80c1789188635a71c0239364615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install google-cloud-storage | |
export GOOGLE_APPLICATION_CREDENTIALS="path/to/your-service-account.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import storage | |
import os | |
# Set your bucket name | |
BUCKET_NAME = "your-bucket-name" | |
# Path to the folder containing images | |
IMAGE_FOLDER = "/path/to/your/images" | |
def upload_to_gcs(bucket_name, source_folder): | |
"""Uploads all images in a folder to Google Cloud Storage.""" | |
client = storage.Client() | |
bucket = client.bucket(bucket_name) | |
for filename in os.listdir(source_folder): | |
file_path = os.path.join(source_folder, filename) | |
if os.path.isfile(file_path): # Ensure it's a file | |
blob = bucket.blob(filename) | |
blob.upload_from_filename(file_path) | |
print(f"Uploaded {filename} to {bucket_name}") | |
if __name__ == "__main__": | |
upload_to_gcs(BUCKET_NAME, IMAGE_FOLDER) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment