Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit bab90b6

Browse files
authored
Merge pull request #154 from supabase-community/fix/cache-control
fix: send cache-control as form data
2 parents 6f64cd2 + 5430e92 commit bab90b6

File tree

4 files changed

+24
-33
lines changed

4 files changed

+24
-33
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
exclude: '^.*\.(md|MD)$'
12
repos:
23
- repo: https://github.com/pre-commit/pre-commit-hooks
34
rev: v4.0.1

docs/api/types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Options
1616

1717
.. autotypeddict:: storage3.types.TransformOptions
1818

19-
.. autotypeddict:: storage3.types.CreateSignedURLOptions
19+
.. autotypeddict:: storage3.types.URLOptions
2020

2121
.. autotypeddict:: storage3.types.CreateSignedURLsOptions
2222

storage3/_async/file_api.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ async def _request(
3737
headers: Optional[dict[str, Any]] = None,
3838
json: Optional[dict[Any, Any]] = None,
3939
files: Optional[Any] = None,
40+
**kwargs: Any,
4041
) -> Response:
4142
response = await self._client.request(
42-
method,
43-
url,
44-
headers=headers or {},
45-
json=json,
46-
files=files,
43+
method, url, headers=headers or {}, json=json, files=files, **kwargs
4744
)
4845
try:
4946
response.raise_for_status()
@@ -108,9 +105,12 @@ async def upload_to_signed_url(
108105
file_options = {}
109106

110107
cache_control = file_options.get("cache-control")
108+
# cacheControl is also passed as form data
109+
# https://github.com/supabase/storage-js/blob/fa44be8156295ba6320ffeff96bdf91016536a46/src/packages/StorageFileApi.ts#L89
110+
_data = {}
111111
if cache_control:
112112
file_options["cache-control"] = f"max-age={cache_control}"
113-
113+
_data = {"cacheControl": cache_control}
114114
headers = {
115115
**self._client.headers,
116116
**DEFAULT_FILE_OPTIONS,
@@ -135,10 +135,7 @@ async def upload_to_signed_url(
135135
)
136136
}
137137
return await self._request(
138-
"PUT",
139-
final_url,
140-
files=_file,
141-
headers=headers,
138+
"PUT", final_url, files=_file, headers=headers, data=_data
142139
)
143140

144141
async def create_signed_url(
@@ -279,7 +276,7 @@ async def copy(self, from_path: str, to_path: str) -> dict[str, str]:
279276
)
280277
return res.json()
281278

282-
async def remove(self, paths: list) -> list[dict[str, any]]:
279+
async def remove(self, paths: list) -> list[dict[str, Any]]:
283280
"""
284281
Deletes files within the same bucket
285282
@@ -369,8 +366,10 @@ async def upload(
369366
if file_options is None:
370367
file_options = {}
371368
cache_control = file_options.get("cache-control")
369+
_data = {}
372370
if cache_control:
373371
file_options["cache-control"] = f"max-age={cache_control}"
372+
_data = {"cacheControl": cache_control}
374373

375374
headers = {
376375
**self._client.headers,
@@ -399,10 +398,7 @@ async def upload(
399398
_path = self._get_final_path(path)
400399

401400
return await self._request(
402-
"POST",
403-
f"/object/{_path}",
404-
files=files,
405-
headers=headers,
401+
"POST", f"/object/{_path}", files=files, headers=headers, data=_data
406402
)
407403

408404
def _get_final_path(self, path: str) -> str:

storage3/_sync/file_api.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ def _request(
3737
headers: Optional[dict[str, Any]] = None,
3838
json: Optional[dict[Any, Any]] = None,
3939
files: Optional[Any] = None,
40+
**kwargs: Any,
4041
) -> Response:
4142
response = self._client.request(
42-
method,
43-
url,
44-
headers=headers or {},
45-
json=json,
46-
files=files,
43+
method, url, headers=headers or {}, json=json, files=files, **kwargs
4744
)
4845
try:
4946
response.raise_for_status()
@@ -108,9 +105,12 @@ def upload_to_signed_url(
108105
file_options = {}
109106

110107
cache_control = file_options.get("cache-control")
108+
# cacheControl is also passed as form data
109+
# https://github.com/supabase/storage-js/blob/fa44be8156295ba6320ffeff96bdf91016536a46/src/packages/StorageFileApi.ts#L89
110+
_data = {}
111111
if cache_control:
112112
file_options["cache-control"] = f"max-age={cache_control}"
113-
113+
_data = {"cacheControl": cache_control}
114114
headers = {
115115
**self._client.headers,
116116
**DEFAULT_FILE_OPTIONS,
@@ -134,12 +134,7 @@ def upload_to_signed_url(
134134
headers.pop("content-type"),
135135
)
136136
}
137-
return self._request(
138-
"PUT",
139-
final_url,
140-
files=_file,
141-
headers=headers,
142-
)
137+
return self._request("PUT", final_url, files=_file, headers=headers, data=_data)
143138

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

282-
def remove(self, paths: list) -> list[dict[str, any]]:
277+
def remove(self, paths: list) -> list[dict[str, Any]]:
283278
"""
284279
Deletes files within the same bucket
285280
@@ -369,8 +364,10 @@ def upload(
369364
if file_options is None:
370365
file_options = {}
371366
cache_control = file_options.get("cache-control")
367+
_data = {}
372368
if cache_control:
373369
file_options["cache-control"] = f"max-age={cache_control}"
370+
_data = {"cacheControl": cache_control}
374371

375372
headers = {
376373
**self._client.headers,
@@ -399,10 +396,7 @@ def upload(
399396
_path = self._get_final_path(path)
400397

401398
return self._request(
402-
"POST",
403-
f"/object/{_path}",
404-
files=files,
405-
headers=headers,
399+
"POST", f"/object/{_path}", files=files, headers=headers, data=_data
406400
)
407401

408402
def _get_final_path(self, path: str) -> str:

0 commit comments

Comments
 (0)