Help Center> Object Storage Service> SDK Reference> Java> Object Upload> Configuring Lifecycle Management

Configuring Lifecycle Management

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

When uploading an object or initializing a multipart upload, you can directly set the expiration time for the object. 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);

PutObjectRequest request = new PutObjectRequest ("bucketname", "objectkey");
request.setFile(new File("localfile"));  // localfile indicates the path of the local file to be uploaded. You need to specify the file name.
// When uploading an object, set the object to expire after 30 days.
request.setExpires(30);
obsClient.putObject(request);


InitiateMultipartUploadRequest request2 = new InitiateMultipartUploadRequest("bucketname", "objectname");
// When initializing a multipart upload, set the object to expire 60 days after combination.
request2.setExpires(60);
obsClient.initiateMultipartUpload(request);
  • The previous mode specifies the time duration in days after which an object will expire. The OBS server automatically clears expired objects.
  • The object expiration time set in the preceding method takes precedence over the bucket lifecycle rule.