-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload-images.py
36 lines (27 loc) · 1.25 KB
/
upload-images.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
from os import scandir
from storage3 import create_client as storage_client
from supabase import create_client, Client
url = "<SUPABSE_URL>"
key = "<SUPABSE_ANON_KEY>"
headers = {"apiKey": key, "Authorization": f"Bearer {key}"}
options = {"contentType": "image/png"}
# pass in is_async=True to create an async client
storage_client = storage_client(url + "/storage/v1", headers, is_async=False)
supabase: Client = create_client(url, key)
UUIDs = [f.path for f in scandir('images/output') if f.is_dir()]
for UUID in UUIDs:
files = [f.path for f in scandir(UUID) if f.is_file()]
supabase_paths = []
for file in files:
supabase_path = os.path.relpath(file, 'images/')
print("Uploading: " + file)
storage_client.get_bucket('images').upload(supabase_path, file, options)
supabase_paths.append(supabase_path)
# Move file so it doesn't get uploaded twice
path = os.path.split(file)[0]
if not os.path.isdir("images/uploaded/" + path):
os.makedirs("images/uploaded/" + path)
os.rename(file, "images/uploaded/" + file)
supabase_uuid = os.path.relpath(UUID, 'images/output/')
supabase.table("profiles").update({"output": supabase_paths}).eq("id", supabase_uuid).execute()