Uploading Objects - Appending
API Description
You can use this API to upload an object in appendable mode and append data to the object.
Method Definition
ObsClient.appendObject(bucketName, objectKey, content, metadata, headers, progressCallback, autoClose)
Request Parameters
|
Field |
Type |
Optional or Mandatory |
Description |
|---|---|---|---|
|
bucketName |
str |
Mandatory |
Bucket name |
|
objectKey |
str |
Mandatory |
Object name or the name of the uploaded object |
|
content |
Mandatory |
Content to be appended |
|
|
metadata |
dict |
Optional |
Customized metadata for the appendable upload. This parameter is effective only during the first appendable object creation. |
|
headers |
Optional |
Additional header of the request for an appendable upload. This parameter is effective only during the first appendable object creation. |
|
|
progressCallback |
callable |
Optional |
Callback function for obtaining the upload progress
NOTE:
This function contains the following parameters in sequence: number of uploaded bytes, total number of bytes, and used time (unit: second). For details about the sample code, see Uploading an Object – Obtaining the Upload Progress. |
|
autoClose |
bool |
Optional |
After the upload is complete, data flow is automatically closed. The default value is True. |
Returned Results
|
Type |
Description |
|---|---|
|
SDK common result object |
|
GetResult.body Type |
Description |
|---|---|
|
Response result of the request for appending an object |
Sample Code
try:
from obs import AppendObjectContent
content = AppendObjectContent()
content.content = 'Hello OBS'
content.position = 0
resp = obsClient.appendObject('bucketname', 'objectkey', content=content)
if resp.status < 300:
print('requestId:', resp.requestId)
print('nextPosition:', resp.body.nextPosition)
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
except:
import traceback
print(traceback.format_exc())
- Objects uploaded using ObsClient.putObject, referred to as normal objects, can overwrite objects uploaded using ObsClient.appendObject, referred to as appendable objects. Data cannot be appended to an appendable object anymore once the object has been overwritten by a normal object.
- When you upload an object for the first time in appendable mode, an exception will be thrown (status code 409) if a normal object with the same name exists.
- The ETag returned for an appendable upload is the ETag for the uploaded content, rather than that of the whole object.
- Data appended each time can be up to 5 GB, and 10,000 times of appendable uploads can be performed on a single object.
- After an appendable upload is complete successfully, you can use body.nextPosition obtained from the returned result or call ObsClient.getObjectMetadata, to get the location for next appending.
Last Article: Uploading Objects - File-Based
Next Article: Uploading Objects - Resumable Transfer
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.