You must restore an Archive or Cold Archive object before you can read it. This topic describes how to restore an Archive or Cold Archive object.

Usage notes

  • When you use packaging tools such as Webpack and Browserify, install OSS SDK for Browser.js by running the npm install ali-oss command.
  • OSS SDK for Browser.js is usually used in browsers. To prevent your AccessKey pair from being exposed, we recommend that you use a temporary access credential generated by Security Token Service (STS) to access OSS.

    For more information about how to set up STS, see Use a temporary credential provided by STS to access OSS in OSS Developer Guide. You can call the AssumeRole operation or use STS SDKs for various programming languages to obtain a temporary access credential. For more information, see STS SDK overview. A temporary access credential contains a security token and a temporary AccessKey pair that consists of an AccessKey ID and an AccessKey secret.

Restoration

If you want to read an Archive object or a Cold Archive object, you must restore the object in advance. It takes several minutes to restore an Archive object and takes several hours to restore a Cold Archive object.

The following section describes the status of an Archive object or a Cold Archive object throughout the restoration process:
  1. By default, an Archive or a Cold Archive object is in the frozen state before restoration.
  2. After you submit a restore request, the object is in the restoring state.
  3. After the server completes the restore task, the object enters the restored state and you can read the object.
    • Archive objects

      For Archive objects, the restored state lasts 24 hours by default. During the 24 hours, if you call RestoreObject again, the restored state is extended by 24 hours. You can extend the restored state to seven days by calling RestoreObject six times during the first 24 hours of restored state. You can also configure the duration of the restored state in days by calling RestoreObject once. You can specify a duration of at most seven days.

    • Cold Archive objects
      For Cold Archive objects, you can specify the duration of restored state and restoration priority. The duration of the restored state must be at least one day and at most 365 days. The time required to restore a Cold Archive object to the readable state is determined based on the restoration priority of the object:
      • Expedited: The object is restored within one hour.
      • Standard: The object is restored within two to five hours. If the JobParameters element is not passed in, the default restoration priority is Standard.
      • Bulk: The object is restored within five to twelve hours.
  4. After the restored state expires, the object returns to the frozen state.

Restore an Archive object

The following code provides an example on how to restore an Archive object:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <title>Document</title>
</head>

<body>
  <button id='upload'>Upload</button>
  <button id='restore'>Restore Object</button>
    <!-- Import the SDK file -->
  <script type="text/javascript" src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.16.0.min.js"></script>
  <script type="text/javascript">
    const client = new OSS({
       // Set yourRegion to the endpoint of the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou. 
       region: 'yourRegion',
       // Specify the temporary AccessKey pair obtained from STS. The AccessKey pair consists of an AccessKey ID and an AccessKey secret. 
       accessKeyId: 'yourAccessKeyId',
       accessKeySecret: 'yourAccessKeySecret',
       // Specify the security token obtained from STS. 
       stsToken: 'yourSecurityToken',
       // Specify the bucket name. Example: examplebucket. 
       bucket: "examplebucket",
    });

    const upload = document.getElementById('upload')
    const restore = document.getElementById('restore')

    // Specify the content of the object to upload. 
    const file = new Blob(['examplecontent'])
    // Specify the name of the object that is uploaded to the bucket. 
    const fileName = 'example.txt'

    // Upload the object and specify its storage class as Archive. 
    upload.addEventListener('click', () => {
      client.put(fileName, file, {
        headers: {
          'x-oss-storage-class': 'Archive'
        }
      }).then(r => console.log(r))
    })
    // Restore the Archive object. 
    restore.addEventListener('click', () => {
      client.restore(fileName).then(r => console.log(r))
    })

  </script>
</body>

</html>

Restore a Cold Archive object

The following code provides an example on how to restore a Cold Archive object:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <title>Document</title>
</head>

<body>
  <button id='upload'>Upload</button>
  <button id='restore'>Restore Object</button>
    <!-- Import the SDK file -->
  <script type="text/javascript" src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.16.0.min.js"></script>
  <script type="text/javascript">
    const client = new OSS({
       // Set yourRegion to the endpoint of the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou. 
       region: 'yourRegion',
       // Specify the temporary AccessKey pair obtained from STS. The AccessKey pair consists of an AccessKey ID and an AccessKey secret. 
       accessKeyId: 'yourAccessKeyId',
       accessKeySecret: 'yourAccessKeySecret',
       // Specify the security token obtained from STS. 
       stsToken: 'yourSecurityToken',
       // Specify the bucket name. Example: examplebucket. 
       bucket: "examplebucket",
    });

    const upload = document.getElementById('upload')
    const restore = document.getElementById('restore')

    // Specify the content of the object to upload. 
    const file = new Blob(['examplecontent'])
    // Specify the name of the object that is uploaded to the bucket. 
    const fileName = 'example.txt'

    // Upload the object and specify its storage class as Cold Archive. 
    upload.addEventListener('click', () => {
      client.put(fileName, file, {
        headers: {
          'x-oss-storage-class': 'ColdArchive'
        }
      }).then(r => console.log(r))
    })
   // type is used to specify the storage class of the object as Cold Archive. 
   // JobParameters is used to specify the restoration priority of the object. 
   // Expedited: The object is restored within one hour. 
   // Standard: The object is restored within two to five hours. If the JobParameters element is not passed in, the default restoration priority is Standard. 
   // Bulk: The object is restored within five to twelve hours. 
   // Days is used to specify the duration in which the object can remain in the restored state. Unit: days. Valid values: 1 to 7. 
   // Restore the Cold Archive object. 
    restore.addEventListener('click', () => {
      client.restore(fileName,{type:'ColdArchive',JobParameters:'Standard',Days:2}).then(r => console.log(r))
    })

  </script>
</body>

</html>

References

  • For more information about the complete sample code that is used to restore an Archive or Cold Archive object, visit GitHub.
  • For more information about the API operation that you can call to restore an Archive or Cold Archive object, see RestoreObject.