|
31 | 31 |
|
32 | 32 | from .utils import ( |
33 | 33 | build_hf_headers, |
| 34 | + fix_hf_endpoint_in_url, |
34 | 35 | get_session, |
35 | 36 | hf_raise_for_status, |
36 | 37 | http_backoff, |
@@ -193,6 +194,7 @@ def lfs_upload( |
193 | 194 | lfs_batch_action: Dict, |
194 | 195 | token: Optional[str] = None, |
195 | 196 | headers: Optional[Dict[str, str]] = None, |
| 197 | + endpoint: Optional[str] = None, |
196 | 198 | ) -> None: |
197 | 199 | """ |
198 | 200 | Handles uploading a given object to the Hub with the LFS protocol. |
@@ -230,22 +232,24 @@ def lfs_upload( |
230 | 232 | # 2. Upload file (either single part or multi-part) |
231 | 233 | header = upload_action.get("header", {}) |
232 | 234 | chunk_size = header.get("chunk_size") |
| 235 | + upload_url = fix_hf_endpoint_in_url(upload_action["href"], endpoint=endpoint) |
233 | 236 | if chunk_size is not None: |
234 | 237 | try: |
235 | 238 | chunk_size = int(chunk_size) |
236 | 239 | except (ValueError, TypeError): |
237 | 240 | raise ValueError( |
238 | 241 | f"Malformed response from LFS batch endpoint: `chunk_size` should be an integer. Got '{chunk_size}'." |
239 | 242 | ) |
240 | | - _upload_multi_part(operation=operation, header=header, chunk_size=chunk_size, upload_url=upload_action["href"]) |
| 243 | + _upload_multi_part(operation=operation, header=header, chunk_size=chunk_size, upload_url=upload_url) |
241 | 244 | else: |
242 | | - _upload_single_part(operation=operation, upload_url=upload_action["href"]) |
| 245 | + _upload_single_part(operation=operation, upload_url=upload_url) |
243 | 246 |
|
244 | 247 | # 3. Verify upload went well |
245 | 248 | if verify_action is not None: |
246 | 249 | _validate_lfs_action(verify_action) |
| 250 | + verify_url = fix_hf_endpoint_in_url(verify_action["href"], endpoint) |
247 | 251 | verify_resp = get_session().post( |
248 | | - verify_action["href"], |
| 252 | + verify_url, |
249 | 253 | headers=build_hf_headers(token=token, headers=headers), |
250 | 254 | json={"oid": operation.upload_info.sha256.hex(), "size": operation.upload_info.size}, |
251 | 255 | ) |
|
0 commit comments