Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Append upload (OSS SDK for Python 1.0)

Son Güncelleme:Oct 01, 2026

Mevcut eklenebilir nesnelere içerik eklemek için AppendObject işlemine çağrı yapabilirsiniz.

Notlar

  • Bu konuda China (Hangzhou) bölgesinin genel uç noktası kullanılmaktadır. OSS ile aynı bölgedeki diğer Alibaba Cloud hizmetlerinden OSS'ye erişmek için dahili bir uç nokta kullanın. OSS bölgeleri ve uç noktaları hakkında daha fazla bilgi için bkz. Bölgeler ve uç noktalar.

  • Bu konuda, bir OSS uç noktası kullanarak bir OSSClient örneği oluşturma işlemi gösterilmektedir. Özel alan adı kullanma veya Security Token Service (STS) kimlik bilgileriyle kimlik doğrulama gibi alternatif yapılandırmalar için bkz. Başlatma.

  • İçerik eklemek istediğiniz nesne mevcut değilse, AppendObject işlemi eklenebilir bir nesne oluşturur.

  • İçerik eklemek istediğiniz nesne mevcutsa:

    • Nesne eklenebilir bir nesneyse ve ekleme işleminin başlayacağı belirtilen konum, mevcut nesne boyutuna eşitse veriler nesnenin sonuna eklenir.

    • Nesne eklenebilir bir nesneyse ve ekleme işleminin başlayacağı belirtilen konum, mevcut nesne boyutuna eşit değilse PositionNotEqualToLength hatası döndürülür.

    • Nesne eklenebilir bir nesne değilse ObjectNotAppendable hatası döndürülür.

İzinler

Varsayılan olarak, bir Alibaba Cloud hesabı tam izinlere sahiptir. Bir Alibaba Cloud hesabı altındaki RAM kullanıcıları veya RAM rollerinde varsayılan olarak herhangi bir izin bulunmaz. Alibaba Cloud hesabı veya hesap yöneticisi, RAM ilkeleri veya Paket İlkesi aracılığıyla işlem izinleri vermelidir.

API

Eylem

Açıklama

AppendObject

oss:PutObject

Bir nesneyi mevcut bir nesneye ekleyerek yüklemek için bu işlemi çağırabilirsiniz.

oss:PutObjectTagging

Bir nesneyi mevcut bir nesneye ekleyerek yüklerken, x-oss-tagging aracılığıyla nesne etiketleri belirtiyorsanız bu izin gereklidir.

Örnekler

Aşağıdaki örnek kod, ekleme yöntemiyle yükleme işleminin nasıl gerçekleştirileceğini göstermektedir:

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"

# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"

# Specify the name of your bucket.
bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region)

# The following code provides an example on how to specify headers for the append upload: 
# headers = dict()
# Specify the caching behavior of the web page for the object. 
# headers['Cache-Control'] = 'no-cache'
# Specify the name of the object when the object is downloaded. 
# headers['Content-Disposition'] = 'oss_MultipartUpload.txt'
# Specify the request header that is used to check whether the content of the received message is the same as the content of the sent message. 
# headers['Content-MD5'] = 'ohhnqLBJFiKkPSBO1eNaUA=='
# Specify the expiration time. 
# headers['Expires'] = 'Wed, 08 Jul 2022 16:57:01 GMT'
# Specify the access control list (ACL) of the object. In this example, the ACL is set to OBJECT_ACL_PRIVATE. 
# headers['x-oss-object-acl'] = oss2.OBJECT_ACL_PRIVATE
# Specify whether to overwrite the object with the same name in the append upload. 
# headers['x-oss-forbid-overwrite'] = 'true'
# Specify the server-side encryption method. In this example, SSE-OSS is specified for server-side encryption. 
# headers[OSS_SERVER_SIDE_ENCRYPTION] = SERVER_SIDE_ENCRYPTION_AES256
# Specify the storage class of the object. 
# headers['x-oss-storage-class'] = oss2.BUCKET_STORAGE_CLASS_STANDARD
# You can add parameters whose names are prefixed with x-oss-meta- when you call the AppendObject operation to create an appendable object. These parameters cannot be included in the requests when you append content to an existing appendable object. Parameters whose names are prefixed with x-oss-meta- are considered the metadata of the object. 
# headers['x-oss-meta-author'] = 'Alice'
# result = bucket.append_object(exampledir/exampleobject.txt, 0, 'content of first append', headers=headers)

# Set the position from which the first append operation starts to 0. 
# Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt. 
result = bucket.append_object('exampledir/exampleobject.txt', 0, 'content of first append')
# If you have appended content to the object, you can obtain the position from which the current append operation starts from the next_position field in the response returned by the last operation or by using bucket.head_object. 
bucket.append_object('<yourObjectName>', result.next_position, 'content of second append')        

İlgili Konular

  • Ekleme yöntemiyle yükleme için eksiksiz örnek kodu görmek üzere GitHub adresini ziyaret edin.

  • Ekleme yöntemiyle yükleme gerçekleştirmek için çağırabileceğiniz API işlemi hakkında daha fazla bilgi için bkz. AppendObject.