Delete objects with versioning (Java SDK V2)
For a versioned bucket, OSS supports temporary deletion or permanent deletion of objects based on whether versionId is specified.
Prerequisites
OSS Java SDK V2 is installed. If you use Maven, add the following dependency to the pom.xml file:
com.aliyun:alibabacloud-oss-v2.Access credentials are configured by using environment variables. The examples in this topic use
EnvironmentVariableCredentialsProviderto read credentials from theOSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables.
Permissions
By default, an Alibaba Cloud account has full permissions. RAM users and RAM roles have no permissions by default. The Alibaba Cloud account owner or an administrator must grant the required permissions.
API | Actions | Description |
DeleteObject, DeleteMultipleObjects |
| Deletes a specified object or multiple objects. |
Delete behavior in versioned buckets
Without versionId (temporary delete): OSS does not delete the current version of the object. Instead, OSS inserts a delete marker above the current version. Subsequent GetObject calls return 404, and the response contains
x-oss-delete-markerand the version ID of the new delete marker inx-oss-version-id.With versionId (permanent delete): OSS permanently deletes the specified version. The deletion cannot be undone. To delete a version whose ID is null, set versionId to
null.
Sample code
References
For API details about deleting a single object, see DeleteObject.
For API details about deleting multiple objects, see DeleteMultipleObjects.
For the synchronous sample code, see DeleteObject.java.
For the synchronous sample code, see DeleteMultipleObjects.java.