import os from supabase import create_client, Client from dotenv import load_dotenv # Load environment variables load_dotenv() # Initialize Supabase Client url = os.getenv("SUPABASE_URL") key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") print(f"DEBUG: URL loaded: {url is not None}") print(f"DEBUG: KEY loaded: {key is not None}") if not url or not key: raise ValueError("Environment variables not loaded correctly!") supabase: Client = create_client(url, key) def upload_file_to_bucket(bucket_name: str, local_file_path: str, destination_path: str): """ Uploads a file to a Supabase storage bucket. """ try: with open(local_file_path, "rb") as f: res = supabase.storage.from_(bucket_name).upload( path=destination_path, file=f, file_options={"content-type": "application/octet-stream"} ) print(f"Successfully uploaded {local_file_path} to {destination_path}") return res except Exception as e: print(f"Error uploading to Supabase: {e}") return None if __name__ == "__main__": print("Supabase uploader initialized.")