|
1 | 1 | from os import PathLike |
2 | 2 | from typing import IO, List, Optional, Union, overload |
3 | 3 | import warnings |
4 | | -from hyperbrowser.exceptions import HyperbrowserError |
5 | | -from ...file_utils import open_binary_file |
6 | 4 | from ..serialization_utils import ( |
7 | 5 | serialize_model_dump_or_default, |
8 | 6 | serialize_model_dump_to_dict, |
9 | 7 | serialize_optional_model_dump_to_dict, |
10 | 8 | ) |
11 | 9 | from ..session_profile_update_utils import resolve_update_profile_params |
12 | | -from ..session_upload_utils import normalize_upload_file_input |
| 10 | +from ..session_upload_utils import open_upload_files_from_input |
13 | 11 | from ..session_utils import ( |
14 | 12 | parse_session_recordings_response_data, |
15 | 13 | parse_session_response_model, |
@@ -168,23 +166,7 @@ async def get_downloads_url(self, id: str) -> GetSessionDownloadsUrlResponse: |
168 | 166 | async def upload_file( |
169 | 167 | self, id: str, file_input: Union[str, PathLike[str], IO] |
170 | 168 | ) -> UploadFileResponse: |
171 | | - file_path, file_obj = normalize_upload_file_input(file_input) |
172 | | - if file_path is not None: |
173 | | - with open_binary_file( |
174 | | - file_path, |
175 | | - open_error_message=f"Failed to open upload file at path: {file_path}", |
176 | | - ) as file_obj: |
177 | | - files = {"file": file_obj} |
178 | | - response = await self._client.transport.post( |
179 | | - self._client._build_url(f"/session/{id}/uploads"), |
180 | | - files=files, |
181 | | - ) |
182 | | - else: |
183 | | - if file_obj is None: |
184 | | - raise HyperbrowserError( |
185 | | - "file_input must be a file path or file-like object" |
186 | | - ) |
187 | | - files = {"file": file_obj} |
| 169 | + with open_upload_files_from_input(file_input) as files: |
188 | 170 | response = await self._client.transport.post( |
189 | 171 | self._client._build_url(f"/session/{id}/uploads"), |
190 | 172 | files=files, |
|
0 commit comments