@@ -2136,11 +2136,11 @@ def load_table_from_file(
2136
2136
try :
2137
2137
if size is None or size >= _MAX_MULTIPART_SIZE :
2138
2138
response = self ._do_resumable_upload (
2139
- file_obj , job_resource , num_retries , timeout
2139
+ file_obj , job_resource , num_retries , timeout , project = project
2140
2140
)
2141
2141
else :
2142
2142
response = self ._do_multipart_upload (
2143
- file_obj , job_resource , size , num_retries , timeout
2143
+ file_obj , job_resource , size , num_retries , timeout , project = project
2144
2144
)
2145
2145
except resumable_media .InvalidResponse as exc :
2146
2146
raise exceptions .from_http_response (exc .response )
@@ -2475,7 +2475,9 @@ def load_table_from_json(
2475
2475
timeout = timeout ,
2476
2476
)
2477
2477
2478
- def _do_resumable_upload (self , stream , metadata , num_retries , timeout ):
2478
+ def _do_resumable_upload (
2479
+ self , stream , metadata , num_retries , timeout , project = None
2480
+ ):
2479
2481
"""Perform a resumable upload.
2480
2482
2481
2483
Args:
@@ -2491,21 +2493,27 @@ def _do_resumable_upload(self, stream, metadata, num_retries, timeout):
2491
2493
The number of seconds to wait for the underlying HTTP transport
2492
2494
before using ``retry``.
2493
2495
2496
+ project (Optional[str]):
2497
+ Project ID of the project of where to run the upload. Defaults
2498
+ to the client's project.
2499
+
2494
2500
Returns:
2495
2501
requests.Response:
2496
2502
The "200 OK" response object returned after the final chunk
2497
2503
is uploaded.
2498
2504
"""
2499
2505
upload , transport = self ._initiate_resumable_upload (
2500
- stream , metadata , num_retries , timeout
2506
+ stream , metadata , num_retries , timeout , project = project
2501
2507
)
2502
2508
2503
2509
while not upload .finished :
2504
2510
response = upload .transmit_next_chunk (transport )
2505
2511
2506
2512
return response
2507
2513
2508
- def _initiate_resumable_upload (self , stream , metadata , num_retries , timeout ):
2514
+ def _initiate_resumable_upload (
2515
+ self , stream , metadata , num_retries , timeout , project = None
2516
+ ):
2509
2517
"""Initiate a resumable upload.
2510
2518
2511
2519
Args:
@@ -2521,6 +2529,10 @@ def _initiate_resumable_upload(self, stream, metadata, num_retries, timeout):
2521
2529
The number of seconds to wait for the underlying HTTP transport
2522
2530
before using ``retry``.
2523
2531
2532
+ project (Optional[str]):
2533
+ Project ID of the project of where to run the upload. Defaults
2534
+ to the client's project.
2535
+
2524
2536
Returns:
2525
2537
Tuple:
2526
2538
Pair of
@@ -2532,7 +2544,11 @@ def _initiate_resumable_upload(self, stream, metadata, num_retries, timeout):
2532
2544
chunk_size = _DEFAULT_CHUNKSIZE
2533
2545
transport = self ._http
2534
2546
headers = _get_upload_headers (self ._connection .user_agent )
2535
- upload_url = _RESUMABLE_URL_TEMPLATE .format (project = self .project )
2547
+
2548
+ if project is None :
2549
+ project = self .project
2550
+ upload_url = _RESUMABLE_URL_TEMPLATE .format (project = project )
2551
+
2536
2552
# TODO: modify ResumableUpload to take a retry.Retry object
2537
2553
# that it can use for the initial RPC.
2538
2554
upload = ResumableUpload (upload_url , chunk_size , headers = headers )
@@ -2553,7 +2569,9 @@ def _initiate_resumable_upload(self, stream, metadata, num_retries, timeout):
2553
2569
2554
2570
return upload , transport
2555
2571
2556
- def _do_multipart_upload (self , stream , metadata , size , num_retries , timeout ):
2572
+ def _do_multipart_upload (
2573
+ self , stream , metadata , size , num_retries , timeout , project = None
2574
+ ):
2557
2575
"""Perform a multipart upload.
2558
2576
2559
2577
Args:
@@ -2574,6 +2592,10 @@ def _do_multipart_upload(self, stream, metadata, size, num_retries, timeout):
2574
2592
The number of seconds to wait for the underlying HTTP transport
2575
2593
before using ``retry``.
2576
2594
2595
+ project (Optional[str]):
2596
+ Project ID of the project of where to run the upload. Defaults
2597
+ to the client's project.
2598
+
2577
2599
Returns:
2578
2600
requests.Response:
2579
2601
The "200 OK" response object returned after the multipart
@@ -2591,7 +2613,10 @@ def _do_multipart_upload(self, stream, metadata, size, num_retries, timeout):
2591
2613
2592
2614
headers = _get_upload_headers (self ._connection .user_agent )
2593
2615
2594
- upload_url = _MULTIPART_URL_TEMPLATE .format (project = self .project )
2616
+ if project is None :
2617
+ project = self .project
2618
+
2619
+ upload_url = _MULTIPART_URL_TEMPLATE .format (project = project )
2595
2620
upload = MultipartUpload (upload_url , headers = headers )
2596
2621
2597
2622
if num_retries is not None :
0 commit comments