Skip to content

Commit c58fbb0

Browse files
fix: file name in signed URLs is not URI-encoded (#324)
1 parent 02ae7fc commit c58fbb0

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

storage3/_async/file_api.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,13 @@ async def create_signed_url(
180180
json=json,
181181
)
182182
data = response.json()
183+
184+
# Prepare URL
185+
url = urllib.parse.urlparse(data["signedURL"])
186+
url = urllib.parse.quote(url.path) + f"?{url.query}"
187+
183188
data["signedURL"] = (
184-
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}{download_query}"
189+
f"{self._client.base_url}{cast(str, url).lstrip('/')}{download_query}"
185190
)
186191
return data
187192

@@ -216,8 +221,13 @@ async def create_signed_urls(
216221
)
217222
data = response.json()
218223
for item in data:
224+
225+
# Prepare URL
226+
url = urllib.parse.urlparse(item["signedURL"])
227+
url = urllib.parse.quote(url.path) + f"?{url.query}"
228+
219229
item["signedURL"] = (
220-
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}{download_query}"
230+
f"{self._client.base_url}{cast(str, url).lstrip('/')}{download_query}"
221231
)
222232
return data
223233

storage3/_sync/file_api.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,13 @@ def create_signed_url(
180180
json=json,
181181
)
182182
data = response.json()
183+
184+
# Prepare URL
185+
url = urllib.parse.urlparse(data["signedURL"])
186+
url = urllib.parse.quote(url.path) + f"?{url.query}"
187+
183188
data["signedURL"] = (
184-
f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}{download_query}"
189+
f"{self._client.base_url}{cast(str, url).lstrip('/')}{download_query}"
185190
)
186191
return data
187192

@@ -216,8 +221,13 @@ def create_signed_urls(
216221
)
217222
data = response.json()
218223
for item in data:
224+
225+
# Prepare URL
226+
url = urllib.parse.urlparse(item["signedURL"])
227+
url = urllib.parse.quote(url.path) + f"?{url.query}"
228+
219229
item["signedURL"] = (
220-
f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}{download_query}"
230+
f"{self._client.base_url}{cast(str, url).lstrip('/')}{download_query}"
221231
)
222232
return data
223233

0 commit comments

Comments
 (0)