Skip to content

put_object: add append object support #1493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# pylint: disable=too-many-lines
# pylint: disable=too-many-public-methods
# pylint: disable=too-many-statements
# pylint: disable=too-many-locals

"""
Simple Storage Service (aka S3) client to perform bucket and object operations.
Expand Down Expand Up @@ -1835,7 +1836,8 @@ def put_object(
num_parallel_uploads: int = 3,
tags: Tags | None = None,
retention: Retention | None = None,
legal_hold: bool = False
legal_hold: bool = False,
write_offset: int | None = None,
) -> ObjectWriteResult:
"""
Uploads data from a stream to an object in a bucket.
Expand All @@ -1854,6 +1856,7 @@ def put_object(
:param tags: :class:`Tags` for the object.
:param retention: :class:`Retention` configuration object.
:param legal_hold: Flag to set legal hold for the object.
:param write_offset: Offset byte for appending data to existing object.
:return: :class:`ObjectWriteResult` object.

Example::
Expand Down Expand Up @@ -1890,13 +1893,21 @@ def put_object(
raise ValueError("retention must be Retention type")
if not callable(getattr(data, "read")):
raise ValueError("input data must have callable read()")
if write_offset is not None:
if write_offset < 0:
raise ValueError("write offset should not be negative")
if length < 0:
raise ValueError("length must be provided for write offset")
part_size = length if length > MIN_PART_SIZE else MIN_PART_SIZE
part_size, part_count = get_part_info(length, part_size)
if progress:
# Set progress bar length and object name before upload
progress.set_meta(object_name=object_name, total_length=length)

headers = genheaders(metadata, sse, tags, retention, legal_hold)
headers["Content-Type"] = content_type or "application/octet-stream"
if write_offset:
headers["x-amz-write-offset-bytes"] = str(write_offset)

object_size = length
uploaded_size = 0
Expand Down