@@ -2782,6 +2782,11 @@ def create_resumable_upload_session(
2782
2782
client = None ,
2783
2783
timeout = _DEFAULT_TIMEOUT ,
2784
2784
checksum = None ,
2785
+ if_generation_match = None ,
2786
+ if_generation_not_match = None ,
2787
+ if_metageneration_match = None ,
2788
+ if_metageneration_not_match = None ,
2789
+ retry = DEFAULT_RETRY_IF_GENERATION_SPECIFIED ,
2785
2790
):
2786
2791
"""Create a resumable upload session.
2787
2792
@@ -2857,6 +2862,41 @@ def create_resumable_upload_session(
2857
2862
delete the uploaded object automatically. Supported values
2858
2863
are "md5", "crc32c" and None. The default is None.
2859
2864
2865
+ :type if_generation_match: long
2866
+ :param if_generation_match:
2867
+ (Optional) See :ref:`using-if-generation-match`
2868
+
2869
+ :type if_generation_not_match: long
2870
+ :param if_generation_not_match:
2871
+ (Optional) See :ref:`using-if-generation-not-match`
2872
+
2873
+ :type if_metageneration_match: long
2874
+ :param if_metageneration_match:
2875
+ (Optional) See :ref:`using-if-metageneration-match`
2876
+
2877
+ :type if_metageneration_not_match: long
2878
+ :param if_metageneration_not_match:
2879
+ (Optional) See :ref:`using-if-metageneration-not-match`
2880
+
2881
+ :type retry: google.api_core.retry.Retry or google.cloud.storage.retry.ConditionalRetryPolicy
2882
+ :param retry: (Optional) How to retry the RPC. A None value will disable
2883
+ retries. A google.api_core.retry.Retry value will enable retries,
2884
+ and the object will define retriable response codes and errors and
2885
+ configure backoff and timeout options.
2886
+ A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a
2887
+ Retry object and activates it only if certain conditions are met.
2888
+ This class exists to provide safe defaults for RPC calls that are
2889
+ not technically safe to retry normally (due to potential data
2890
+ duplication or other side-effects) but become safe to retry if a
2891
+ condition such as if_metageneration_match is set.
2892
+ See the retry.py source code and docstrings in this package
2893
+ (google.cloud.storage.retry) for information on retry types and how
2894
+ to configure them.
2895
+ Media operations (downloads and uploads) do not support non-default
2896
+ predicates in a Retry object. The default will always be used. Other
2897
+ configuration changes for Retry objects such as delays and deadlines
2898
+ are respected.
2899
+
2860
2900
:rtype: str
2861
2901
:returns: The resumable upload session URL. The upload can be
2862
2902
completed by making an HTTP PUT request with the
@@ -2865,6 +2905,19 @@ def create_resumable_upload_session(
2865
2905
:raises: :class:`google.cloud.exceptions.GoogleCloudError`
2866
2906
if the session creation response returns an error status.
2867
2907
"""
2908
+
2909
+ # Handle ConditionalRetryPolicy.
2910
+ if isinstance (retry , ConditionalRetryPolicy ):
2911
+ # Conditional retries are designed for non-media calls, which change
2912
+ # arguments into query_params dictionaries. Media operations work
2913
+ # differently, so here we make a "fake" query_params to feed to the
2914
+ # ConditionalRetryPolicy.
2915
+ query_params = {
2916
+ "ifGenerationMatch" : if_generation_match ,
2917
+ "ifMetagenerationMatch" : if_metageneration_match ,
2918
+ }
2919
+ retry = retry .get_retry_policy_if_conditions_met (query_params = query_params )
2920
+
2868
2921
extra_headers = {}
2869
2922
if origin is not None :
2870
2923
# This header is specifically for client-side uploads, it
@@ -2883,10 +2936,15 @@ def create_resumable_upload_session(
2883
2936
size ,
2884
2937
None ,
2885
2938
predefined_acl = None ,
2939
+ if_generation_match = if_generation_match ,
2940
+ if_generation_not_match = if_generation_not_match ,
2941
+ if_metageneration_match = if_metageneration_match ,
2942
+ if_metageneration_not_match = if_metageneration_not_match ,
2886
2943
extra_headers = extra_headers ,
2887
2944
chunk_size = self ._CHUNK_SIZE_MULTIPLE ,
2888
2945
timeout = timeout ,
2889
2946
checksum = checksum ,
2947
+ retry = retry ,
2890
2948
)
2891
2949
2892
2950
return upload .resumable_url
0 commit comments