Skip to content

Commit 748067f

Browse files
authored
fix: add correct return data for upload to signed url (#309)
1 parent fca2f00 commit 748067f

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

storage3/_async/file_api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def upload_to_signed_url(
8686
token: str,
8787
file: Union[BufferedReader, bytes, FileIO, str, Path],
8888
file_options: Optional[FileOptions] = None,
89-
) -> Response:
89+
) -> UploadResponse:
9090
"""
9191
Upload a file with a token generated from :meth:`.create_signed_url`
9292
@@ -139,9 +139,12 @@ async def upload_to_signed_url(
139139
headers.pop("content-type"),
140140
)
141141
}
142-
return await self._request(
142+
response = await self._request(
143143
"PUT", final_url, files=_file, headers=headers, data=_data
144144
)
145+
data: UploadData = response.json()
146+
147+
return UploadResponse(path=path, Key=data.get("Key"))
145148

146149
async def create_signed_url(
147150
self, path: str, expires_in: int, options: URLOptions = {}

storage3/_sync/file_api.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def upload_to_signed_url(
8686
token: str,
8787
file: Union[BufferedReader, bytes, FileIO, str, Path],
8888
file_options: Optional[FileOptions] = None,
89-
) -> Response:
89+
) -> UploadResponse:
9090
"""
9191
Upload a file with a token generated from :meth:`.create_signed_url`
9292
@@ -139,7 +139,12 @@ def upload_to_signed_url(
139139
headers.pop("content-type"),
140140
)
141141
}
142-
return self._request("PUT", final_url, files=_file, headers=headers, data=_data)
142+
response = self._request(
143+
"PUT", final_url, files=_file, headers=headers, data=_data
144+
)
145+
data: UploadData = response.json()
146+
147+
return UploadResponse(path=path, Key=data.get("Key"))
143148

144149
def create_signed_url(
145150
self, path: str, expires_in: int, options: URLOptions = {}

tests/_async/test_client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,15 @@ async def test_client_upload_to_signed_url(
331331
"""Ensure we can upload to a signed URL"""
332332
data = await storage_file_client.create_signed_upload_url(file.bucket_path)
333333
assert data["path"]
334-
upload_result = await storage_file_client.upload_to_signed_url(
334+
await storage_file_client.upload_to_signed_url(
335335
data["path"], data["token"], file.file_content, {"content-type": file.mime_type}
336336
)
337-
upload_data = upload_result.json()
338-
assert upload_data
339-
assert upload_data.get("error") is None
337+
image = await storage_file_client.download(file.bucket_path)
338+
files = await storage_file_client.list(file.bucket_folder)
339+
image_info = next((f for f in files if f.get("name") == file.name), None)
340+
341+
assert image == file.file_content
342+
assert image_info.get("metadata", {}).get("mimetype") == file.mime_type
340343

341344

342345
async def test_client_create_signed_url(

tests/_sync/test_client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,15 @@ def test_client_upload_to_signed_url(
329329
"""Ensure we can upload to a signed URL"""
330330
data = storage_file_client.create_signed_upload_url(file.bucket_path)
331331
assert data["path"]
332-
upload_result = storage_file_client.upload_to_signed_url(
332+
storage_file_client.upload_to_signed_url(
333333
data["path"], data["token"], file.file_content, {"content-type": file.mime_type}
334334
)
335-
upload_data = upload_result.json()
336-
assert upload_data
337-
assert upload_data.get("error") is None
335+
image = storage_file_client.download(file.bucket_path)
336+
files = storage_file_client.list(file.bucket_folder)
337+
image_info = next((f for f in files if f.get("name") == file.name), None)
338+
339+
assert image == file.file_content
340+
assert image_info.get("metadata", {}).get("mimetype") == file.mime_type
338341

339342

340343
def test_client_create_signed_url(

0 commit comments

Comments
 (0)