@@ -2136,11 +2136,11 @@ def load_table_from_file(
21362136 try :
21372137 if size is None or size >= _MAX_MULTIPART_SIZE :
21382138 response = self ._do_resumable_upload (
2139- file_obj , job_resource , num_retries , timeout
2139+ file_obj , job_resource , num_retries , timeout , project = project
21402140 )
21412141 else :
21422142 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
21442144 )
21452145 except resumable_media .InvalidResponse as exc :
21462146 raise exceptions .from_http_response (exc .response )
@@ -2475,7 +2475,9 @@ def load_table_from_json(
24752475 timeout = timeout ,
24762476 )
24772477
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+ ):
24792481 """Perform a resumable upload.
24802482
24812483 Args:
@@ -2491,21 +2493,27 @@ def _do_resumable_upload(self, stream, metadata, num_retries, timeout):
24912493 The number of seconds to wait for the underlying HTTP transport
24922494 before using ``retry``.
24932495
2496+ project (Optional[str]):
2497+ Project ID of the project of where to run the upload. Defaults
2498+ to the client's project.
2499+
24942500 Returns:
24952501 requests.Response:
24962502 The "200 OK" response object returned after the final chunk
24972503 is uploaded.
24982504 """
24992505 upload , transport = self ._initiate_resumable_upload (
2500- stream , metadata , num_retries , timeout
2506+ stream , metadata , num_retries , timeout , project = project
25012507 )
25022508
25032509 while not upload .finished :
25042510 response = upload .transmit_next_chunk (transport )
25052511
25062512 return response
25072513
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+ ):
25092517 """Initiate a resumable upload.
25102518
25112519 Args:
@@ -2521,6 +2529,10 @@ def _initiate_resumable_upload(self, stream, metadata, num_retries, timeout):
25212529 The number of seconds to wait for the underlying HTTP transport
25222530 before using ``retry``.
25232531
2532+ project (Optional[str]):
2533+ Project ID of the project of where to run the upload. Defaults
2534+ to the client's project.
2535+
25242536 Returns:
25252537 Tuple:
25262538 Pair of
@@ -2532,7 +2544,11 @@ def _initiate_resumable_upload(self, stream, metadata, num_retries, timeout):
25322544 chunk_size = _DEFAULT_CHUNKSIZE
25332545 transport = self ._http
25342546 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+
25362552 # TODO: modify ResumableUpload to take a retry.Retry object
25372553 # that it can use for the initial RPC.
25382554 upload = ResumableUpload (upload_url , chunk_size , headers = headers )
@@ -2553,7 +2569,9 @@ def _initiate_resumable_upload(self, stream, metadata, num_retries, timeout):
25532569
25542570 return upload , transport
25552571
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+ ):
25572575 """Perform a multipart upload.
25582576
25592577 Args:
@@ -2574,6 +2592,10 @@ def _do_multipart_upload(self, stream, metadata, size, num_retries, timeout):
25742592 The number of seconds to wait for the underlying HTTP transport
25752593 before using ``retry``.
25762594
2595+ project (Optional[str]):
2596+ Project ID of the project of where to run the upload. Defaults
2597+ to the client's project.
2598+
25772599 Returns:
25782600 requests.Response:
25792601 The "200 OK" response object returned after the multipart
@@ -2591,7 +2613,10 @@ def _do_multipart_upload(self, stream, metadata, size, num_retries, timeout):
25912613
25922614 headers = _get_upload_headers (self ._connection .user_agent )
25932615
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 )
25952620 upload = MultipartUpload (upload_url , headers = headers )
25962621
25972622 if num_retries is not None :
0 commit comments