如果您不熟悉 Amazon Simple Storage Service (Amazon S3) 中的归档存储功能,建议您先详细了解 Amazon S3 中的 S3 Glacier 存储类、S3 Glacier 即时检索、S3 Glacier 灵活检索和 S3 Glacier 深度归档。有关更多信息,请参阅 Amazon S3 用户指南中的 S3 Glacier 存储类
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用Amazon SDK for Java从 S3 Glacier 的文件库中删除档案
以下代码示例使用Amazon SDK for Java来删除档案。在代码中,请注意以下情况:
-
DeleteArchiveRequest
数据元描述删除请求,包括档案所在的文件库名称和档案 ID。 -
deleteArchive
API 操作向 Amazon S3 Glacier 发送删除档案的请求。 -
该示例使用美国西部(俄勒冈州)区域 (
us-west-2
)。
有关如何运行以下示例的分步说明,请参阅使用 Eclipse 运行 Amazon S3 Glacier 的 Java 示例。您需要更新 步骤 3:在 S3 Glacier 中将存档上传到文件库 中已上传文件的档案 ID 旁显示的代码。
例 —使用Amazon SDK for Java删除档案
import java.io.IOException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.glacier.AmazonGlacierClient; import com.amazonaws.services.glacier.model.DeleteArchiveRequest; public class AmazonGlacierDeleteArchive_GettingStarted { public static String vaultName = "examplevault"; public static String archiveId = "*** provide archive ID***"; public static AmazonGlacierClient client; public static void main(String[] args) throws IOException { ProfileCredentialsProvider credentials = new ProfileCredentialsProvider(); client = new AmazonGlacierClient(credentials); client.setEndpoint("https://glacier.us-west-2.amazonaws.com/"); try { // Delete the archive. client.deleteArchive(new DeleteArchiveRequest() .withVaultName(vaultName) .withArchiveId(archiveId)); System.out.println("Deleted archive successfully."); } catch (Exception e) { System.err.println("Archive not deleted."); System.err.println(e); } } }