Help Center> Object Storage Service> SDK Reference> Java> Object Upload> Performing an Appendable Upload

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:

String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";

// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

// Upload an object in appendable mode.
AppendObjectRequest request = new AppendObjectRequest();
request.setBucketName("bucketname");
request.setObjectKey("objectname");
request.setPosition(0);
request.setInput(new ByteArrayInputStream("Hello OBS".getBytes()));
AppendObjectResult result = obsClient.appendObject(request);
              
// Append data to the object.
request.setPosition(result.getNextPosition());
request.setInput(new ByteArrayInputStream("Hello OBS Again".getBytes()));
result = obsClient.appendObject(request);

System.out.println("NextPosition:" + result.getNextPosition());
System.out.println("Etag:" + result.getEtag());
// Use the API for obtaining object properties to get the start position for next appending.
ObjectMetadata metadata = obsClient.getObjectMetadata("bucketname", "objectname");
System.out.println("NextPosition from metadata:" + metadata.getNextPosition());
  • 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 successful, you can call AppendObjectResult.getNextPosition or use the ObsClient.getObjectMetadata API to get the start position for next appending.