private static void Main(string[] args)
var ak = Environment.GetEnvironmentVariable("TOS_ACCESS_KEY");
var sk = Environment.GetEnvironmentVariable("TOS_SECRET_KEY");
var endpoint = "https://tos-cn-beijing.volces.com";
var region = "cn-beijing";
var bucketName = "*** Provide your bucket name ***";
var objectContent = "your append object value";
var objectKey = "example_dir/example.txt";
var localFileName = "/usr/local/test.txt";
var client = TosClientBuilder.Builder().SetAk(ak).SetSk(sk).SetEndpoint(endpoint).SetRegion(region).Build();
var binaryData = Encoding.UTF8.GetBytes(objectContent);
AppendObjectOutput appendObjectOutput;
using (var requestContent = new MemoryStream(binaryData))
var appendObjectInput = new AppendObjectInput
Content = requestContent
appendObjectOutput = client.AppendObject(appendObjectInput);
Console.WriteLine("Append object succeeded, request id: {0} ", appendObjectOutput.RequestID);
using (var fileStream = File.OpenRead(localFileName))
var appendObjectInput = new AppendObjectInput
Offset = appendObjectOutput.NextAppendOffset,
appendObjectOutput = client.AppendObject(appendObjectInput);
Console.WriteLine("Append object succeeded, request id: {0} ", appendObjectOutput.RequestID);
catch (TosServerException ex)
Console.WriteLine("Put object failed, request id {0}", ex.RequestID);
Console.WriteLine("Put object failed, status code {0}", ex.StatusCode);
Console.WriteLine("Put object failed, response error code {0}", ex.Code);
Console.WriteLine("Put object failed, response error message {0}", ex.Message);
catch (TosClientException ex)
Console.WriteLine("Put object failed, error message {0}", ex.Message);
Console.WriteLine("Put object failed, {0}", ex.Message);