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?
I think the method is exactly what you need: CloudBlockBlob.SetStandardBlobTier. Maybe you were not checking the latest version of Azure Storage Client Library?
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With