Performing an Appendable Upload
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
Appendable upload allows you to upload an object in appendable mode and then append data to the object. You can call ObsClient.AppendObject to perform an appendable upload. Sample code is as follows:
// Create an instance of ObsClient.
ObsClient client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", "https://your-endpoint");
try
{
// Upload an object in appendable mode.
AppendObjectRequest request = new AppendObjectRequest();
request.BucketName = "bucketname";
request.ObjectKey = "objectkey";
request.InputStream = new MemoryStream(Encoding.UTF8.GetBytes("Hello OBS"));
AppendObjectResponse response = client.AppendObject(request);
// Append data to the object.
request.Position = response.NextPosition;
request.InputStream = new MemoryStream(Encoding.UTF8.GetBytes("Hello OBS Again"));
response = client.AppendObject(request);
Console.WriteLine("NextPosition:{0}", response.NextPosition);
Console.WriteLine("ETag:{0}", response.ETag);
// Use the API for obtaining object properties to get the start position for next appending.
GetObjectMetadataResponse metadataResponse = client.GetObjectMetadata("bucketname", "objectkey");
Console.WriteLine("NextPosition from metadata:{0}", metadataResponse.NextPosition);
}
catch (ObsException ex)
{
Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
Console.WriteLine("ErrorMessage: {0}", ex.ErrorMessage);
}
- 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 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 each append 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 10000 times of appendable uploads can be performed on a single object.
- After an appendable upload is successful, you can use AppendObjectResponse.NextPosition or call ObsClient.GetObjectMetadata to get the start position for next appending.
Last Article: Configuring Lifecycle Management
Next Article: Performing a Multipart Copy
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.