From fca8ceb484c4811f561c9d67321441784f5b7f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vitor=20de=20Aquino?= <67425140+jv-aquino@users.noreply.github.com> Date: Mon, 24 Jul 2023 13:30:38 -0300 Subject: [PATCH] Add Storage examples --- README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/README.md b/README.md index c4808759..4a322578 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,82 @@ resp = loop.run_until_complete(test_func(loop)) loop.close() ``` +## Storage + +### Download a file + +```python +from supabase import create_client, Client + +url: str = os.environ.get("SUPABASE_TEST_URL") +key: str = os.environ.get("SUPABASE_TEST_KEY") +supabase: Client = create_client(url, key) + +bucket_name: str = "photos" + +data = supabase.storage.from_(bucket_name).download("photo1.png) +``` + +### Upload a file + +```python +from supabase import create_client, Client + +url: str = os.environ.get("SUPABASE_TEST_URL") +key: str = os.environ.get("SUPABASE_TEST_KEY") +supabase: Client = create_client(url, key) + +bucket_name: str = "photos" +new_file = getUserFile() + +data = supabase.storage.from_(bucket_name).upload("/user1/profile.png", new_file) +``` + +### Delete a file + +```python +from supabase import create_client, Client + +url: str = os.environ.get("SUPABASE_TEST_URL") +key: str = os.environ.get("SUPABASE_TEST_KEY") +supabase: Client = create_client(url, key) + +bucket_name: str = "photos" + +data = supabase.storage.from_(bucket_name).delete(["old_photo.png", "image5.jpg"]) +``` + +### List all files + +```python +from supabase import create_client, Client + +url: str = os.environ.get("SUPABASE_TEST_URL") +key: str = os.environ.get("SUPABASE_TEST_KEY") +supabase: Client = create_client(url, key) + +bucket_name: str = "charts" + +data = supabase.storage.from_(bucket_name).list() +``` + +### Move and rename file + +```python +from supabase import create_client, Client + +url: str = os.environ.get("SUPABASE_TEST_URL") +key: str = os.environ.get("SUPABASE_TEST_KEY") +supabase: Client = create_client(url, key) + +bucket_name: str = "charts" +old_file_path: str = "generic/graph1.png" +new_file_path: str = "important/revenue.png" + +data = supabase.storage.from_(bucket_name).move(old_file_path, new_file_path) +``` + + ## Realtime Changes Realtime changes are unfortunately still a WIP. Feel free to file PRs to [realtime-py](https://github.com/supabase-community/realtime-py)