Amazon Simple Storage Service
开发人员指南 (API 版本 2006-03-01)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

使用 AWS SDK for Java 还原存档对象

以下示例说明如何使用AWS SDK for Java还原已存档到 Amazon Glacier 的对象。该示例为指定的存档对象启动还原请求并检查其还原状态。有关还原已存档对象的更多信息,请参阅恢复存档对象。有关创建和测试有效示例的说明,请参阅测试 Amazon S3 Java 代码示例

import; import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import; import; import; import; public class RestoreArchivedObject { public static void main(String[] args) throws IOException { String clientRegion = "*** Client region ***"; String bucketName = "*** Bucket name ***"; String keyName = "*** Object key ***"; try { AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withCredentials(new ProfileCredentialsProvider()) .withRegion(clientRegion) .build(); // Create and submit a request to restore an object from Glacier for two days. RestoreObjectRequest requestRestore = new RestoreObjectRequest(bucketName, keyName, 2); s3Client.restoreObjectV2(requestRestore); // Check the restoration status of the object. ObjectMetadata response = s3Client.getObjectMetadata(bucketName, keyName); Boolean restoreFlag = response.getOngoingRestore(); System.out.format("Restoration status: %s.\n", restoreFlag ? "in progress" : "not in progress (finished or failed)"); } catch(AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 couldn't process // it, so it returned an error response. e.printStackTrace(); } catch(SdkClientException e) { // Amazon S3 couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3. e.printStackTrace(); } } }