• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Java SDK)
  4. Object Upload
  5. Performing an Appendable Upload

Performing an Appendable Upload

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 = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
String uploadId = "upload id from initiateMultipartUpload";
// 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("objectkey");
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", "objectkey");
System.out.println("NextPosition from metadata:" + metadata.getNextPosition());

obsClient.close();
NOTE:
  • 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 each 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 10000 times of appendable uploads can be performed on a single object.
  • After an appendable upload is performed successfully, you can call AppendObjectResult.getNextPosition or use the API for obtaining object properties, to get the location for next appending.