Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exclude: '^.*\.(md|MD)$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
Expand Down
2 changes: 1 addition & 1 deletion docs/api/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Options

.. autotypeddict:: storage3.types.TransformOptions

.. autotypeddict:: storage3.types.CreateSignedURLOptions
.. autotypeddict:: storage3.types.URLOptions

.. autotypeddict:: storage3.types.CreateSignedURLsOptions

Expand Down
26 changes: 11 additions & 15 deletions storage3/_async/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ async def _request(
headers: Optional[dict[str, Any]] = None,
json: Optional[dict[Any, Any]] = None,
files: Optional[Any] = None,
**kwargs: Any,
) -> Response:
response = await self._client.request(
method,
url,
headers=headers or {},
json=json,
files=files,
method, url, headers=headers or {}, json=json, files=files, **kwargs
)
try:
response.raise_for_status()
Expand Down Expand Up @@ -108,9 +105,12 @@ async def upload_to_signed_url(
file_options = {}

cache_control = file_options.get("cache-control")
# cacheControl is also passed as form data
# https://github.com/supabase/storage-js/blob/fa44be8156295ba6320ffeff96bdf91016536a46/src/packages/StorageFileApi.ts#L89
_data = {}
if cache_control:
file_options["cache-control"] = f"max-age={cache_control}"

_data = {"cacheControl": cache_control}
headers = {
**self._client.headers,
**DEFAULT_FILE_OPTIONS,
Expand All @@ -135,10 +135,7 @@ async def upload_to_signed_url(
)
}
return await self._request(
"PUT",
final_url,
files=_file,
headers=headers,
"PUT", final_url, files=_file, headers=headers, data=_data
)

async def create_signed_url(
Expand Down Expand Up @@ -279,7 +276,7 @@ async def copy(self, from_path: str, to_path: str) -> dict[str, str]:
)
return res.json()

async def remove(self, paths: list) -> list[dict[str, any]]:
async def remove(self, paths: list) -> list[dict[str, Any]]:
"""
Deletes files within the same bucket

Expand Down Expand Up @@ -369,8 +366,10 @@ async def upload(
if file_options is None:
file_options = {}
cache_control = file_options.get("cache-control")
_data = {}
if cache_control:
file_options["cache-control"] = f"max-age={cache_control}"
_data = {"cacheControl": cache_control}

headers = {
**self._client.headers,
Expand Down Expand Up @@ -399,10 +398,7 @@ async def upload(
_path = self._get_final_path(path)

return await self._request(
"POST",
f"/object/{_path}",
files=files,
headers=headers,
"POST", f"/object/{_path}", files=files, headers=headers, data=_data
)

def _get_final_path(self, path: str) -> str:
Expand Down
28 changes: 11 additions & 17 deletions storage3/_sync/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ def _request(
headers: Optional[dict[str, Any]] = None,
json: Optional[dict[Any, Any]] = None,
files: Optional[Any] = None,
**kwargs: Any,
) -> Response:
response = self._client.request(
method,
url,
headers=headers or {},
json=json,
files=files,
method, url, headers=headers or {}, json=json, files=files, **kwargs
)
try:
response.raise_for_status()
Expand Down Expand Up @@ -108,9 +105,12 @@ def upload_to_signed_url(
file_options = {}

cache_control = file_options.get("cache-control")
# cacheControl is also passed as form data
# https://github.com/supabase/storage-js/blob/fa44be8156295ba6320ffeff96bdf91016536a46/src/packages/StorageFileApi.ts#L89
_data = {}
if cache_control:
file_options["cache-control"] = f"max-age={cache_control}"

_data = {"cacheControl": cache_control}
headers = {
**self._client.headers,
**DEFAULT_FILE_OPTIONS,
Expand All @@ -134,12 +134,7 @@ def upload_to_signed_url(
headers.pop("content-type"),
)
}
return self._request(
"PUT",
final_url,
files=_file,
headers=headers,
)
return self._request("PUT", final_url, files=_file, headers=headers, data=_data)

def create_signed_url(
self, path: str, expires_in: int, options: URLOptions = {}
Expand Down Expand Up @@ -279,7 +274,7 @@ def copy(self, from_path: str, to_path: str) -> dict[str, str]:
)
return res.json()

def remove(self, paths: list) -> list[dict[str, any]]:
def remove(self, paths: list) -> list[dict[str, Any]]:
"""
Deletes files within the same bucket

Expand Down Expand Up @@ -369,8 +364,10 @@ def upload(
if file_options is None:
file_options = {}
cache_control = file_options.get("cache-control")
_data = {}
if cache_control:
file_options["cache-control"] = f"max-age={cache_control}"
_data = {"cacheControl": cache_control}

headers = {
**self._client.headers,
Expand Down Expand Up @@ -399,10 +396,7 @@ def upload(
_path = self._get_final_path(path)

return self._request(
"POST",
f"/object/{_path}",
files=files,
headers=headers,
"POST", f"/object/{_path}", files=files, headers=headers, data=_data
)

def _get_final_path(self, path: str) -> str:
Expand Down