2020# pylint: disable=too-many-lines
2121# pylint: disable=too-many-public-methods
2222# pylint: disable=too-many-statements
23+ # pylint: disable=too-many-locals
2324
2425"""
2526Simple Storage Service (aka S3) client to perform bucket and object operations.
@@ -1835,7 +1836,8 @@ def put_object(
18351836 num_parallel_uploads : int = 3 ,
18361837 tags : Tags | None = None ,
18371838 retention : Retention | None = None ,
1838- legal_hold : bool = False
1839+ legal_hold : bool = False ,
1840+ write_offset : int | None = None ,
18391841 ) -> ObjectWriteResult :
18401842 """
18411843 Uploads data from a stream to an object in a bucket.
@@ -1854,6 +1856,7 @@ def put_object(
18541856 :param tags: :class:`Tags` for the object.
18551857 :param retention: :class:`Retention` configuration object.
18561858 :param legal_hold: Flag to set legal hold for the object.
1859+ :param write_offset: Offset byte for appending data to existing object.
18571860 :return: :class:`ObjectWriteResult` object.
18581861
18591862 Example::
@@ -1890,13 +1893,21 @@ def put_object(
18901893 raise ValueError ("retention must be Retention type" )
18911894 if not callable (getattr (data , "read" )):
18921895 raise ValueError ("input data must have callable read()" )
1896+ if write_offset is not None :
1897+ if write_offset < 0 :
1898+ raise ValueError ("write offset should not be negative" )
1899+ if length < 0 :
1900+ raise ValueError ("length must be provided for write offset" )
1901+ part_size = length if length > MIN_PART_SIZE else MIN_PART_SIZE
18931902 part_size , part_count = get_part_info (length , part_size )
18941903 if progress :
18951904 # Set progress bar length and object name before upload
18961905 progress .set_meta (object_name = object_name , total_length = length )
18971906
18981907 headers = genheaders (metadata , sse , tags , retention , legal_hold )
18991908 headers ["Content-Type" ] = content_type or "application/octet-stream"
1909+ if write_offset :
1910+ headers ["x-amz-write-offset-bytes" ] = str (write_offset )
19001911
19011912 object_size = length
19021913 uploaded_size = 0
0 commit comments