Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add correct return data for upload to signed url #309

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions storage3/_async/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def upload_to_signed_url(
token: str,
file: Union[BufferedReader, bytes, FileIO, str, Path],
file_options: Optional[FileOptions] = None,
) -> Response:
) -> UploadResponse:
"""
Upload a file with a token generated from :meth:`.create_signed_url`

Expand Down Expand Up @@ -139,9 +139,12 @@ async def upload_to_signed_url(
headers.pop("content-type"),
)
}
return await self._request(
response = await self._request(
"PUT", final_url, files=_file, headers=headers, data=_data
)
data: UploadData = response.json()

return UploadResponse(path=path, Key=data.get("Key"))

async def create_signed_url(
self, path: str, expires_in: int, options: URLOptions = {}
Expand Down
9 changes: 7 additions & 2 deletions storage3/_sync/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def upload_to_signed_url(
token: str,
file: Union[BufferedReader, bytes, FileIO, str, Path],
file_options: Optional[FileOptions] = None,
) -> Response:
) -> UploadResponse:
"""
Upload a file with a token generated from :meth:`.create_signed_url`

Expand Down Expand Up @@ -139,7 +139,12 @@ def upload_to_signed_url(
headers.pop("content-type"),
)
}
return self._request("PUT", final_url, files=_file, headers=headers, data=_data)
response = self._request(
"PUT", final_url, files=_file, headers=headers, data=_data
)
data: UploadData = response.json()

return UploadResponse(path=path, Key=data.get("Key"))

def create_signed_url(
self, path: str, expires_in: int, options: URLOptions = {}
Expand Down
11 changes: 7 additions & 4 deletions tests/_async/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,15 @@ async def test_client_upload_to_signed_url(
"""Ensure we can upload to a signed URL"""
data = await storage_file_client.create_signed_upload_url(file.bucket_path)
assert data["path"]
upload_result = await storage_file_client.upload_to_signed_url(
await storage_file_client.upload_to_signed_url(
data["path"], data["token"], file.file_content, {"content-type": file.mime_type}
)
upload_data = upload_result.json()
assert upload_data
assert upload_data.get("error") is None
image = await storage_file_client.download(file.bucket_path)
files = await storage_file_client.list(file.bucket_folder)
image_info = next((f for f in files if f.get("name") == file.name), None)

assert image == file.file_content
assert image_info.get("metadata", {}).get("mimetype") == file.mime_type


async def test_client_create_signed_url(
Expand Down
11 changes: 7 additions & 4 deletions tests/_sync/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,15 @@ def test_client_upload_to_signed_url(
"""Ensure we can upload to a signed URL"""
data = storage_file_client.create_signed_upload_url(file.bucket_path)
assert data["path"]
upload_result = storage_file_client.upload_to_signed_url(
storage_file_client.upload_to_signed_url(
data["path"], data["token"], file.file_content, {"content-type": file.mime_type}
)
upload_data = upload_result.json()
assert upload_data
assert upload_data.get("error") is None
image = storage_file_client.download(file.bucket_path)
files = storage_file_client.list(file.bucket_folder)
image_info = next((f for f in files if f.get("name") == file.name), None)

assert image == file.file_content
assert image_info.get("metadata", {}).get("mimetype") == file.mime_type


def test_client_create_signed_url(
Expand Down
Loading