Updated on 2024-06-21 GMT+08:00

Downloading an Archive Object

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference.

Before you can download an Archive object, you must restore it. Archive objects can be restored in either of the following ways.

Option

Description

Value in OBS Android SDK

Expedited restore

Data can be restored within 1 to 5 minutes.

RestoreTierEnum.EXPEDITED

Standard restore

Data can be restored within 3 to 5 hours. This is the default option.

RestoreTierEnum.STANDARD

To extend the validity period of the Archive data restored, you can repeatedly restore the data, but you will be billed for each restore. After a second restore, the validity period of Standard object copies will be extended, and you need to pay for storing these copies during the extended period.

You can call ObsClient.restoreObject to restore an Archive object. Sample code is as follows:

// Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID.
// Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
String ak = System.getenv("ACCESS_KEY_ID");
String sk = System.getenv("SECRET_ACCESS_KEY_ID");
String endPoint = "https://your-endpoint";
// Create an ObsClient instance.
final ObsClient obsClient = new ObsClient(ak, sk, endPoint);

RestoreObjectRequest request = new RestoreObjectRequest();
request.setBucketName("bucketname");
request.setObjectKey("objectname");
request.setDays(1);
request.setRestoreTier(RestoreTierEnum.EXPEDITED);
obsClient.restoreObject(request);

// Wait for the object to be restored.
Thread.sleep(60 * 6 * 1000);

// Download an object.
ObsObject obsObject = obsClient.getObject("bucketname", "objectname");

obsObject.getObjectContent().close();
  • The object specified in ObsClient.restoreObject must be in the OBS Archive storage class. Otherwise, an exception will be thrown when you call this API.
  • RestoreObjectRequest.setDays specifies the retention period of restored objects, ranging from 1 to 30.
  • RestoreObjectRequest.setTier specifies the restore option, which indicates the time spent on restoring objects.