Skip to content

Commit 27e90f6

Browse files
Joel LeeJoel Lee
Joel Lee
authored and
Joel Lee
committed
fix: get create_signed_url working
1 parent 047e680 commit 27e90f6

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

Diff for: supabase_py/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from supabase_py.lib.auth_client import SupabaseAuthClient
66
from supabase_py.lib.query_builder import SupabaseQueryBuilder
77
from supabase_py.lib.realtime_client import SupabaseRealtimeClient
8-
from supabase_py.lib.supabase_storage_client import SupabaseStorageClient
8+
from supabase_py.lib.storage_client import SupabaseStorageClient
99

1010
DEFAULT_OPTIONS = {
1111
"schema": "public",

Diff for: supabase_py/lib/storage/storage_file_api.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from requests import HTTPError
33

44

5-
class StorageFileApi:
5+
class StorageFileAPI:
66
DEFAULT_SEARCH_OPTIONS = {
77
"limit": 100,
88
"offset": 0,
@@ -28,7 +28,6 @@ def __init__(self, url: str, headers: dict, bucket_id: str):
2828
self.bucket_id = bucket_id
2929
# self.loop = asyncio.get_event_loop()
3030
# self.replace = replace
31-
pass
3231

3332
def create_signed_url(self, path: str, expires_in: int):
3433
"""
@@ -41,14 +40,12 @@ def create_signed_url(self, path: str, expires_in: int):
4140
"""
4241
try:
4342
_path = self._get_final_path(path)
44-
print(f"{self.url}/object/sign/{_path}")
4543
response = requests.post(
4644
f"{self.url}/object/sign/{_path}",
4745
json={"expiresIn": str(expires_in)},
4846
headers=self.headers,
4947
)
5048
data = response.json()
51-
print(data)
5249
data["signedURL"] = f"{self.url}{data['signedURL']}"
5350
response.raise_for_status()
5451
except HTTPError as http_err:
@@ -58,6 +55,20 @@ def create_signed_url(self, path: str, expires_in: int):
5855
else:
5956
return data
6057

58+
def get_public_url(self, path: str):
59+
"""
60+
Parameters
61+
----------
62+
path
63+
file path to be downloaded, including the path and file name. For example `folder/image.png`.
64+
"""
65+
try:
66+
_path = self._get_final_path(path)
67+
public_url = f"{self.url}/object/public/{_path}"
68+
return public_url
69+
except:
70+
print("Public URL not found")
71+
6172
def move(self, from_path: str, to_path: str):
6273
"""
6374
Moves an existing file, optionally renaming it at the same time.

Diff for: supabase_py/lib/storage_client.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from supabase_py.lib.storage.storage_bucket_api import StorageBucketAPI
2+
from supabase_py.lib.storage.storage_file_api import StorageFileAPI
3+
4+
5+
class SupabaseStorageClient(StorageBucketAPI):
6+
"""
7+
Manage the storage bucket and files
8+
Examples
9+
--------
10+
>>> url = storage_file.create_signed_url("something/test2.txt", 80) # signed url
11+
>>> loop.run_until_complete(storage_file.download("something/test2.txt")) # upload or download
12+
>>> loop.run_until_complete(storage_file.upload("something/test2.txt","path_file_upload"))
13+
>>> list_buckets = storage.list_buckets()
14+
>>> list_files = storage_file.list("something")
15+
"""
16+
17+
def __init__(self, url, headers):
18+
super().__init__(url, headers)
19+
20+
def StorageFileAPI(self, id_):
21+
return StorageFileAPI(self.url, self.headers, id_)

Diff for: supabase_py/lib/supabase_storage_client.py

-24
This file was deleted.

0 commit comments

Comments
 (0)