All Products
Search
Document Center

Object Storage Service:Restore objects (OSS SDK for Java 1.0)

Last Updated:Mar 01, 2026

Archive, Cold Archive, and Deep Cold Archive objects must be restored before you can access them. This topic describes how to restore objects in each storage class by using OSS SDK for Java 1.0.

Archive objects support real-time access as an alternative to restoration. Real-time access is not available for Cold Archive or Deep Cold Archive objects.

Restoration time by storage class

Storage classRestoration tierSDK constantEstimated time
Archive(default)N/ASeveral minutes
Cold ArchiveExpeditedRestoreTier.RESTORE_TIER_EXPEDITEDWithin 1 hour
Cold ArchiveStandardRestoreTier.RESTORE_TIER_STANDARD2 to 5 hours
Cold ArchiveBulkRestoreTier.RESTORE_TIER_BULK5 to 12 hours
Deep Cold ArchiveExpeditedRestoreTier.RESTORE_TIER_EXPEDITEDWithin 12 hours
Deep Cold ArchiveStandardRestoreTier.RESTORE_TIER_STANDARDWithin 48 hours

Actual restoration times may vary.

Prerequisites

Before you begin, make sure that you have:

  • An Alibaba Cloud account with the oss:RestoreObject permission. For details, see Attach a custom policy to a RAM user

  • The OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables configured. For details, see Configure access credentials

  • An OSS bucket containing Archive, Cold Archive, or Deep Cold Archive objects

The RestoreObject operation applies only to Archive, Cold Archive, and Deep Cold Archive objects. This operation does not apply to Standard or Infrequent Access (IA) objects.
The examples in this topic use the public endpoint of the China (Hangzhou) region. To access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For supported regions and endpoints, see Regions and endpoints.
The examples create an OSSClient instance by using an OSS endpoint. To use a custom domain or authenticate with Security Token Service (STS) credentials, see Client configuration.

Restore an Archive object

Call restoreObject with the bucket name and object key. Then poll getObjectMetadata until the restoration completes before you access the object.

import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.*;

public class Demo {
    public static void main(String[] args) throws Exception {
        // Endpoint for the China (Hangzhou) region. Replace with your actual endpoint.
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // Load AccessKey credentials from environment variables.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Bucket name
        String bucketName = "examplebucket";
        // Full path of the object (excluding the bucket name)
        String objectName = "exampledir/object";
        // Region ID
        String region = "cn-hangzhou";

        // Create an OSSClient instance with V4 signature.
        // Call shutdown() to release resources when finished.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
        .endpoint(endpoint)
        .credentialsProvider(credentialsProvider)
        .clientConfiguration(clientBuilderConfiguration)
        .region(region)
        .build();

        try {
            ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucketName, objectName);

            // Verify the object is stored in the Archive storage class.
            StorageClass storageClass = objectMetadata.getObjectStorageClass();
            if (storageClass == StorageClass.Archive) {
                // Initiate the restore request.
                ossClient.restoreObject(bucketName, objectName);

                // Poll until the restore completes.
                do {
                    Thread.sleep(1000);
                    objectMetadata = ossClient.getObjectMetadata(bucketName, objectName);
                } while (!objectMetadata.isRestoreCompleted());
            }

            // Access the restored object.
            OSSObject ossObject = ossClient.getObject(bucketName, objectName);
            ossObject.getObjectContent().close();
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}

Restore a Cold Archive object

Cold Archive objects require a RestoreConfiguration that specifies the restoration tier and the number of days the object remains in the restored state.

ParameterDescriptionDefault
daysNumber of days the object stays in the restored state1
jobParametersRestoration tier: RESTORE_TIER_EXPEDITED, RESTORE_TIER_STANDARD, or RESTORE_TIER_BULKN/A
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.*;

public class Demo {
    public static void main(String[] args) throws Exception {
        // Endpoint for the China (Hangzhou) region. Replace with your actual endpoint.
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // Load AccessKey credentials from environment variables.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Bucket name
        String bucketName = "examplebucket";
        // Full path of the object (excluding the bucket name)
        String objectName = "exampledir/object";
        // Region ID
        String region = "cn-hangzhou";

        // Create an OSSClient instance with V4 signature.
        // Call shutdown() to release resources when finished.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
        .endpoint(endpoint)
        .credentialsProvider(credentialsProvider)
        .clientConfiguration(clientBuilderConfiguration)
        .region(region)
        .build();

        try {
            // Set the restoration tier for a Cold Archive object:
            //   RESTORE_TIER_EXPEDITED  - within 1 hour
            //   RESTORE_TIER_STANDARD   - within 2 to 5 hours
            //   RESTORE_TIER_BULK       - within 5 to 12 hours
            RestoreJobParameters jobParameters = new RestoreJobParameters(RestoreTier.RESTORE_TIER_BULK);

            // Keep the object in restored state for 2 days (default: 1 day).
            RestoreConfiguration configuration = new RestoreConfiguration(2, jobParameters);

            // Initiate the restore request.
            ossClient.restoreObject(bucketName, objectName, configuration);
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}

Restore a Deep Cold Archive object

Deep Cold Archive objects use the same RestoreConfiguration pattern but support only two restoration tiers: Expedited (within 12 hours) and Standard (within 48 hours).

import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.*;

public class Demo {
    public static void main(String[] args) throws Exception {
        // Endpoint for the China (Hangzhou) region. Replace with your actual endpoint.
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // Load AccessKey credentials from environment variables.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Bucket name
        String bucketName = "examplebucket";
        // Full path of the object (excluding the bucket name)
        String objectName = "exampledir/object";
        // Region ID
        String region = "cn-hangzhou";

        // Create an OSSClient instance with V4 signature.
        // Call shutdown() to release resources when finished.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
        .endpoint(endpoint)
        .credentialsProvider(credentialsProvider)
        .clientConfiguration(clientBuilderConfiguration)
        .region(region)
        .build();

        try {
            // Set the restoration tier for a Deep Cold Archive object:
            //   RESTORE_TIER_EXPEDITED  - within 12 hours
            //   RESTORE_TIER_STANDARD   - within 48 hours
            RestoreJobParameters jobParameters = new RestoreJobParameters(RestoreTier.RESTORE_TIER_STANDARD);

            // Keep the object in restored state for 2 days (default: 1 day).
            RestoreConfiguration configuration = new RestoreConfiguration(2, jobParameters);

            // Initiate the restore request.
            ossClient.restoreObject(bucketName, objectName, configuration);
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}

References