Skip to content

Commit

Permalink
fix: pass cache-control as formdata
Browse files Browse the repository at this point in the history
  • Loading branch information
anand2312 committed Sep 29, 2023
1 parent 5ad2ae8 commit 9910fe0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
24 changes: 10 additions & 14 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 @@ -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
26 changes: 10 additions & 16 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 @@ -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

0 comments on commit 9910fe0

Please sign in to comment.