Skip to content

Commit

Permalink
fix: file name in signed URLs is not URI-encoded (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco authored Dec 24, 2024
1 parent 02ae7fc commit c58fbb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions storage3/_async/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,13 @@ async def create_signed_url(
json=json,
)
data = response.json()

# Prepare URL
url = urllib.parse.urlparse(data["signedURL"])
url = urllib.parse.quote(url.path) + f"?{url.query}"

data["signedURL"] = (
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}{download_query}"
f"{self._client.base_url}{cast(str, url).lstrip('/')}{download_query}"
)
return data

Expand Down Expand Up @@ -216,8 +221,13 @@ async def create_signed_urls(
)
data = response.json()
for item in data:

# Prepare URL
url = urllib.parse.urlparse(item["signedURL"])
url = urllib.parse.quote(url.path) + f"?{url.query}"

item["signedURL"] = (
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}{download_query}"
f"{self._client.base_url}{cast(str, url).lstrip('/')}{download_query}"
)
return data

Expand Down
14 changes: 12 additions & 2 deletions storage3/_sync/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,13 @@ def create_signed_url(
json=json,
)
data = response.json()

# Prepare URL
url = urllib.parse.urlparse(data["signedURL"])
url = urllib.parse.quote(url.path) + f"?{url.query}"

data["signedURL"] = (
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}{download_query}"
f"{self._client.base_url}{cast(str, url).lstrip('/')}{download_query}"
)
return data

Expand Down Expand Up @@ -216,8 +221,13 @@ def create_signed_urls(
)
data = response.json()
for item in data:

# Prepare URL
url = urllib.parse.urlparse(item["signedURL"])
url = urllib.parse.quote(url.path) + f"?{url.query}"

item["signedURL"] = (
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}{download_query}"
f"{self._client.base_url}{cast(str, url).lstrip('/')}{download_query}"
)
return data

Expand Down

0 comments on commit c58fbb0

Please sign in to comment.