操作 | 命令/代码示例 |
查看 Java SDK 版本 | System.out.println(com.amazonaws.SDKVersionInfo.VERSION); |
删除特定版本的 S3 对象(如果使用 AWS S3) | amazonS3.deleteObject(new DeleteObjectRequest(bucketName, key).withVersionId(versionId)); |
删除所有版本的 S3 对象(如果使用 AWS S3) | 以下是一个循环,用于删除所有版本的对象: |
| ListVersionsRequest listVersionsRequest = new ListVersionsRequest().withBucketName(bucketName).withPrefix(key); |
| VersionListing versionListing = amazonS3.listVersions(listVersionsRequest); |
| while (true) { |
| for (S3VersionSummary versionSummary : versionListing.getVersionSummaries()) { |
| amazonS3.deleteVersion(new DeleteVersionRequest(bucketName, key, versionSummary.getVersionId())); |
| } |
| if (versionListing.isTruncated()) { |
| versionListing = amazonS3.listNextBatchOfVersions(versionListing); |
| } else { |
| break; |
| } |
| } |