Skip to content

Commit fca8ceb

Browse files
authoredJul 24, 2023
Add Storage examples
1 parent cb8566a commit fca8ceb

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
 

‎README.md

+76
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,82 @@ resp = loop.run_until_complete(test_func(loop))
206206
loop.close()
207207
```
208208

209+
## Storage
210+
211+
### Download a file
212+
213+
```python
214+
from supabase import create_client, Client
215+
216+
url: str = os.environ.get("SUPABASE_TEST_URL")
217+
key: str = os.environ.get("SUPABASE_TEST_KEY")
218+
supabase: Client = create_client(url, key)
219+
220+
bucket_name: str = "photos"
221+
222+
data = supabase.storage.from_(bucket_name).download("photo1.png)
223+
```
224+
225+
### Upload a file
226+
227+
```python
228+
from supabase import create_client, Client
229+
230+
url: str = os.environ.get("SUPABASE_TEST_URL")
231+
key: str = os.environ.get("SUPABASE_TEST_KEY")
232+
supabase: Client = create_client(url, key)
233+
234+
bucket_name: str = "photos"
235+
new_file = getUserFile()
236+
237+
data = supabase.storage.from_(bucket_name).upload("/user1/profile.png", new_file)
238+
```
239+
240+
### Delete a file
241+
242+
```python
243+
from supabase import create_client, Client
244+
245+
url: str = os.environ.get("SUPABASE_TEST_URL")
246+
key: str = os.environ.get("SUPABASE_TEST_KEY")
247+
supabase: Client = create_client(url, key)
248+
249+
bucket_name: str = "photos"
250+
251+
data = supabase.storage.from_(bucket_name).delete(["old_photo.png", "image5.jpg"])
252+
```
253+
254+
### List all files
255+
256+
```python
257+
from supabase import create_client, Client
258+
259+
url: str = os.environ.get("SUPABASE_TEST_URL")
260+
key: str = os.environ.get("SUPABASE_TEST_KEY")
261+
supabase: Client = create_client(url, key)
262+
263+
bucket_name: str = "charts"
264+
265+
data = supabase.storage.from_(bucket_name).list()
266+
```
267+
268+
### Move and rename file
269+
270+
```python
271+
from supabase import create_client, Client
272+
273+
url: str = os.environ.get("SUPABASE_TEST_URL")
274+
key: str = os.environ.get("SUPABASE_TEST_KEY")
275+
supabase: Client = create_client(url, key)
276+
277+
bucket_name: str = "charts"
278+
old_file_path: str = "generic/graph1.png"
279+
new_file_path: str = "important/revenue.png"
280+
281+
data = supabase.storage.from_(bucket_name).move(old_file_path, new_file_path)
282+
```
283+
284+
209285
## Realtime Changes
210286

211287
Realtime changes are unfortunately still a WIP. Feel free to file PRs to [realtime-py](https://github.com/supabase-community/realtime-py)

0 commit comments

Comments
 (0)
Please sign in to comment.