c# Azure Cannot set the blob tier
Asked Answered
M

3

7

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://learn.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?

Man answered 4/4, 2018 at 20:55 Comment(0)
J
9

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

Jacktar answered 4/4, 2018 at 22:49 Comment(2)
Ah I must need to update the npm packages I guess, I'll take a look at this later, thanks.Man
It's a dead link now. I think this is the one you want now: learn.microsoft.com/en-us/dotnet/api/…Zoraidazorana
F
7

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

Forborne answered 6/4, 2018 at 6:6 Comment(0)
G
5

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.

Gilburt answered 2/6, 2020 at 21:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.