This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
This article shows how to set or change a blob'saccess tier for block blobs with theAzure Storage client library for JavaScript.
To manage costs for storage needs, it can be helpful to organize your data based on how frequently it's accessed and how long it needs to be retained. Azure storage offers different access tiers so that you can store your blob data in the most cost-effective manner based on how it's being used.
Azure Storage access tiers include:
To learn more about access tiers, seeAccess tiers for blob data.
While a blob is in the Archive access tier, it's considered to be offline, and can't be read or modified. In order to read or modify data in an archived blob, you must first rehydrate the blob to an online tier. To learn more about rehydrating a blob from the Archive tier to an online tier, seeBlob rehydration from the Archive tier.
Setting the access tier is only allowed on block blobs. To learn more about restrictions on setting a block blob's access tier, seeSet Blob Tier (REST API).
Note
To set the access tier toCold using JavaScript, you must use a minimumclient library version of 12.13.0.
Toupload a blob into a specific access tier, use theBlockBlobUploadOptions. Thetier property choices are:Hot,Cool,Cold, orArchive.
async function uploadWithAccessTier(containerClient, blobName) { const fileContentsAsString = `Hello from a string` // upload blob to `Cool` access tier const uploadOptions = { // 'Hot', 'Cool', 'Cold', or 'Archive' tier: 'Cool', } // Create blob client from container client const blockBlobClient = containerClient.getBlockBlobClient(blobName); // Upload string await blockBlobClient.upload(fileContentsAsString, fileContentsAsString.length, uploadOptions); // Return client to continue with other operations return blockBlobClient;}To change the access tier of a blob after it's uploaded to storage, usesetAccessTier. Along with the tier, you can set theBlobSetTierOptions propertyrehydration priority to bring the block blob out of an archived state. Possible values areHigh orStandard.
async function main(blockBlobClient) { // Get current access tier const { accessTier } = await blockBlobClient.getProperties(); console.log(`Current access tier: ${accessTier}`); // 'Hot', 'Cool', or 'Archive' const newAccessTier = 'Cool'; // Rehydrate priority: 'High' or 'Standard' const rehydratePriority = 'High'; const result = await blockBlobClient.setAccessTier( newAccessTier, { rehydratePriority } ); if (result?.errorCode == undefined) { console.log(`Change to access was successful`); } else { console.log(result); }}Use the BlobClient.beginCopyFromURL method to copy a blob. To change the access tier during the copy operation, use theBlobBeginCopyFromURLOptionstier property and specify a different accesstier than the source blob.
async function copyBlobWithDifferentAccessTier(containerClient) { // create blob clients const sourceBlobClient = containerClient.getBlobClient(originalBlob); const destinationBlobClient = containerClient.getBlobClient(copyBlob); // start copy, access tiers include `Hot`, `Cool`, `Cold`, `Archive` const copyPoller = await destinationBlobClient.beginCopyFromURL(sourceBlobClient.url, { tier: 'Hot' }); console.log('start copy from original to copy'); // wait until done await copyPoller.pollUntilDone(); console.log('copy finished')}The batch represents an aggregated set of operations on blobs, such asdelete orset 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 aBlobBatchClient. Use the client to create a batch with thecreateBatch() method. When the batch is ready,submit the batch for processing. Use the returned structure to validate each blob's operation was successful.
async function main(containerClient) { // Prep array const blockBlobCount = 3; const blockBlobClients = new Array(blockBlobCount); // Create container and blobs in `Hot` tier await prepContainer(containerClient, blockBlobCount, blockBlobClients); // Blob batch client and batch const containerScopedBatchClient = containerClient.getBlobBatchClient(); const blobBatch = containerScopedBatchClient.createBatch(); // Assemble batch to set tier to `Cool` tier for (let i = 0; i < blockBlobCount; i++) { await blobBatch.setBlobAccessTier(blockBlobClients[i].url, sharedKeyCredential, "Cool", {}); } // Submit batch request and verify response const resp = await containerScopedBatchClient.submitBatch(blobBatch, {}); console.log(`Requested ${blockBlobCount}, batched ${resp.subResponses.length}, success ${resp.subResponsesSucceededCount}, failure ${resp.subResponsesFailedCount}`); // Examine each batch item for (let i = 0; i < blockBlobCount; i++) { // Check blob tier set properly const resp2 = await blockBlobClients[i].getProperties(); console.log(`[${i}] access tier ${resp2.accessTier}, status ${resp.subResponses[i].status}, message ${resp.subResponses[i].statusMessage}`) }}Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?