Skip to content

Latest commit

 

History

History
103 lines (61 loc) · 7.76 KB

File metadata and controls

103 lines (61 loc) · 7.76 KB
title Set or change a blob's access tier with JavaScript or TypeScript
titleSuffix Azure Storage
description Learn how to set or change a blob's access tier in your Azure Storage account using the JavaScript client library.
services storage
author stevenmatthew
ms.author shaas
ms.service azure-blob-storage
ms.topic how-to
ms.date 10/28/2024
ms.devlang javascript
ms.custom devx-track-js, devguide-js, devx-track-ts, devguide-ts

Set or change a block blob's access tier with JavaScript or TypeScript

[!INCLUDE storage-dev-guide-selector-access-tier]

This article shows how to set or change a blob's access tier for block blobs with the Azure Storage client library for JavaScript.

Prerequisites

  • The examples in this article assume you already have a project set up to work with the Azure Blob Storage client library for JavaScript. To learn about setting up your project, including package installation, importing modules, and creating an authorized client object to work with data resources, see Get started with Azure Blob Storage and JavaScript.
  • The authorization mechanism must have permissions to set the blob's access tier. To learn more, see the authorization guidance for the following REST API operation:

[!INCLUDE storage-dev-guide-about-access-tiers]

Note

To set the access tier to Cold using JavaScript, you must use a minimum client library version of 12.13.0.

Set a blob's access tier during upload

To upload a blob into a specific access tier, use the BlockBlobUploadOptions. The tier property choices are: Hot, Cool, Cold, or Archive.

:::code language="javascript" source="~/azure-storage-snippets/blobs/howto/JavaScript/NodeJS-v12/dev-guide/upload-blob-from-string-with-access-tier.js" id="Snippet_UploadAccessTier" highlight="13-15, 26":::

:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-upload-from-string-with-access-tier.ts" id="Snippet_UploadAccessTier" :::


Change a blob's access tier after upload

To change the access tier of a blob after it's uploaded to storage, use setAccessTier. Along with the tier, you can set the BlobSetTierOptions property rehydration priority to bring the block blob out of an archived state. Possible values are High or Standard.

:::code language="javascript" source="~/azure-storage-snippets/blobs/howto/JavaScript/NodeJS-v12/dev-guide/change-blob-access-tier.js" id="Snippet_BatchChangeAccessTier" highlight="8,11,13-16":::

:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-change-access-tier.ts" id="Snippet_BlobChangeAccessTier" :::


Copy a blob into a different access tier

Use the BlobClient.beginCopyFromURL method to copy a blob. To change the access tier during the copy operation, use the BlobBeginCopyFromURLOptions tier property and specify a different access tier than the source blob.

:::code language="javascript" source="~/azure-storage-snippets/blobs/howto/JavaScript/NodeJS-v12/dev-guide/copy-blob-to-different-access-tier.js" id="Snippet_CopyWithAccessTier" highlight="8":::

:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-copy-to-different-access-tier.ts" id="Snippet_CopyWithAccessTier" :::


Use a batch to change access tier for many blobs

The batch represents an aggregated set of operations on blobs, such as delete or set access tier. You need to pass in the correct credential to successfully perform each operation. In this example, the same credential is used for a set of blobs in the same container.

Create a BlobBatchClient. Use the client to create a batch with the createBatch() method. When the batch is ready, submit the batch for processing. Use the returned structure to validate each blob's operation was successful.

:::code language="javascript" source="~/azure-storage-snippets/blobs/howto/JavaScript/NodeJS-v12/dev-guide/batch-set-access-tier.js" id="Snippet_BatchChangeAccessTier" highlight="16,20":::

:::code language="typescript" source="~/azure-storage-snippets/blobs/howto/TypeScript/NodeJS-v12/dev-guide/src/blob-batch-set-access-tier-for-container.ts" id="Snippet_BatchChangeAccessTier" :::


Code samples

Next steps