All Products
Search
Document Center

Object Storage Service:Restore files (Browser.js SDK)

Last Updated:Mar 20, 2026

Archive and Cold Archive objects must be restored before they can be read. This topic describes how to restore Archive and Cold Archive objects using OSS SDK for Browser.js.

Prerequisites

Before you begin, ensure that you have:

  • An OSS bucket containing Archive or Cold Archive objects

  • Cross-Origin Resource Sharing (CORS) rules configured for the bucket. Without CORS rules, the browser rejects requests to OSS. For more information, see Installation

  • Temporary access credentials from Security Token Service (STS). Because OSS SDK for Browser.js runs in the browser, use STS temporary credentials instead of a long-term AccessKey pair to avoid exposing your AccessKey ID and AccessKey secret. For more information, see Use STS for temporary access authorization

When using packaging tools such as Webpack or Browserify, install OSS SDK for Browser.js by running npm install ali-oss.

Restoration priorities for Cold Archive objects

Before submitting a Cold Archive restore request, choose a restoration priority based on how quickly you need access to the object:

PriorityRestoration timeUse when
ExpeditedWithin 1 hourYou need access urgently
Standard2–5 hoursStandard timing is acceptable (default)
Bulk5–12 hoursSpeed is not critical and you want to minimize cost

The Days parameter specifies how long the object remains in the restored state. The valid range is 1–7 days, with a default of 1 day.

Restore an Archive object

The following example uploads a file with the Archive storage class and then restores it. Call client.restore(fileName) to initiate the restore.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Document</title>
</head>
<body>
  <button id='upload'>Upload</button>
  <button id='restore'>Restore File</button>
  <!-- Import the SDK file. -->
  <script type="text/javascript" src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.18.0.min.js"></script>
  <script type="text/javascript">
    const client = new OSS({
      // Set region to the region where the bucket is located.
      // Example: oss-cn-hangzhou for the China (Hangzhou) region.
      region: 'yourRegion',
      authorizationV4: true,
      // Temporary AccessKey ID and AccessKey secret obtained from STS.
      accessKeyId: 'yourAccessKeyId',
      accessKeySecret: 'yourAccessKeySecret',
      // Security token obtained from STS.
      stsToken: 'yourSecurityToken',
      // The bucket name.
      bucket: 'examplebucket',
    });

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

    // Specify the file content and object name.
    const file = new Blob(['examplecontent']);
    const fileName = 'example.txt';

    // Upload the file with the Archive storage class.
    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

For Cold Archive objects, pass the type, JobParameters, and Days options to client.restore(). The following example uses Bulk priority and a 2-day restoration window.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Document</title>
</head>
<body>
  <button id='upload'>Upload</button>
  <button id='restore'>Restore File</button>
  <!-- Import the SDK file. -->
  <script type="text/javascript" src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.18.0.min.js"></script>
  <script type="text/javascript">
    const client = new OSS({
      // Set region to the region where the bucket is located.
      // Example: oss-cn-hangzhou for the China (Hangzhou) region.
      region: 'yourRegion',
      authorizationV4: true,
      // Temporary AccessKey ID and AccessKey secret obtained from STS.
      accessKeyId: 'yourAccessKeyId',
      accessKeySecret: 'yourAccessKeySecret',
      // Security token obtained from STS.
      stsToken: 'yourSecurityToken',
      // The bucket name.
      bucket: 'examplebucket',
    });

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

    // Specify the file content and object name.
    const file = new Blob(['examplecontent']);
    const fileName = 'example1.txt';

    // Upload the file with the Cold Archive storage class.
    upload.addEventListener('click', () => {
      client.put(fileName, file, {
        headers: {
          'x-oss-storage-class': 'ColdArchive',
        },
      }).then(r => console.log(r));
    });

    // Restore the Cold Archive object.
    // JobParameters: Expedited (within 1 hour), Standard (2-5 hours), or Bulk (5-12 hours).
    // Days: the number of days the object remains in the restored state (1-7, default: 1).
    restore.addEventListener('click', () => {
      client.restore(fileName, {
        type: 'ColdArchive',
        JobParameters: 'Bulk',
        Days: 2,
      }).then(r => console.log(r));
    });
  </script>
</body>
</html>

References