Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Azure Cannot set the blob tier

CloudBlockBlob doesn't have any method to set the blob tier to hot/cool/archive. I have also checked the other blob types and they do not have a method that allows this either.

I.E this method: https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier

Is their any way to change the blob tier in code from hot to cold in C# with azure storage?

like image 804
Martin Dawson Avatar asked Apr 04 '18 20:04

Martin Dawson


3 Answers

I think the method is exactly what you need: CloudBlockBlob.SetStandardBlobTier. Maybe you were not checking the latest version of Azure Storage Client Library?

like image 196
Zhaoxing Lu Avatar answered Sep 22 '22 10:09

Zhaoxing Lu


Is their any way to change the blob tier in code from hot to cold in C# with azure storage?

As ZhaoXing Lu mentioned that we could use CloudBlockBlob.SetStandardBlobTier.

Note: The operation is allowed on a page blob in a premium storage account and on a block blob in a blob storage account

The following code works correctly on my side. I use the library WindowsAzure.Storage 9.1.1

var cloudBlobClient = storageAccount.CreateCloudBlobClient();
var container = cloudBlobClient.GetContainerReference("container");
var blob = container.GetBlockBlobReference("blob name");
blob.SetStandardBlobTier(StandardBlobTier.Cool);
blob.FetchAttributes();
var tier = blob.Properties.StandardBlobTier;

enter image description here

like image 40
Tom Sun - MSFT Avatar answered Sep 18 '22 10:09

Tom Sun - MSFT


Using Azure Blob storage client library v12 for .NET, replace myaccount with the name of your storage account, mycontainer with your container name and myblob with the blob name for which the tier is to be changed:

var sharedKeyCredential = new StorageSharedKeyCredential("myaccount", storageAccountKey);
var baseBlobContainerUrl = string.Format("{0}.blob.core.windows.net", "myaccount");
var blobServiceClient = new BlobServiceClient(new Uri($"https://{baseBlobContainerUrl}"), sharedKeyCredential);
var containerClient = blobServiceClient.GetBlobContainerClient("mycontainer");
BlobClient blobClient = containerClient.GetBlobClient("myblob");
// Set access tier to cool.
await blobClient.SetAccessTierAsync(AccessTier.Cool);

If you are working with Azure Gov, use this url insteadl "{0}.blob.core.usgovcloudapi.net"

Keep in mind, your storage account should support Cool Storage.

like image 42
VictorV Avatar answered Sep 20 '22 10:09

VictorV