diff --git a/storage3/_async/file_api.py b/storage3/_async/file_api.py index f3a31c46..6113a6bd 100644 --- a/storage3/_async/file_api.py +++ b/storage3/_async/file_api.py @@ -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` @@ -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 = {} diff --git a/storage3/_sync/file_api.py b/storage3/_sync/file_api.py index c0854bd2..ce69c5a8 100644 --- a/storage3/_sync/file_api.py +++ b/storage3/_sync/file_api.py @@ -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` @@ -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 = {} diff --git a/tests/_async/test_client.py b/tests/_async/test_client.py index 7c9c283e..aba9361d 100644 --- a/tests/_async/test_client.py +++ b/tests/_async/test_client.py @@ -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( diff --git a/tests/_sync/test_client.py b/tests/_sync/test_client.py index 9cf62421..e82a427e 100644 --- a/tests/_sync/test_client.py +++ b/tests/_sync/test_client.py @@ -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(