ईवेंट्स
31 मार्च, 11 pm - 2 अप्रैल, 11 pm
सबसे बड़ा फैब्रिक, Power BI और SQL सीखने का इवेंट। मार्च 31 - अप्रैल 2। $ 400 बचाने के लिए कोड FABINSIDER का उपयोग करें।
आज पंजीकरण करेंयह ब्राउज़र अब समर्थित नहीं है.
नवीनतम सुविधाओं, सुरक्षा अपडेट और तकनीकी सहायता का लाभ लेने के लिए Microsoft Edge में अपग्रेड करें.
This article shows how to set or change the access tier for a block blob using the Azure Storage client library for .NET.
If you don't have an existing project, this section shows you how to set up a project to work with the Azure Blob Storage client library for .NET. The steps include package installation, adding using
directives, and creating an authorized client object. For details, see Get started with Azure Blob Storage and .NET.
From your project directory, install packages for the Azure Blob Storage and Azure Identity client libraries using the dotnet add package
command. The Azure.Identity package is needed for passwordless connections to Azure services.
dotnet add package Azure.Storage.Blobs
dotnet add package Azure.Identity
Add these using
directives to the top of your code file:
using Azure.Identity;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
Some code examples in this article might require additional using
directives.
To connect an app to Blob Storage, create an instance of BlobServiceClient. The following example shows how to create a client object using DefaultAzureCredential
for authorization:
public BlobServiceClient GetBlobServiceClient(string accountName)
{
BlobServiceClient client = new(
new Uri($"https://{accountName}.blob.core.windows.net"),
new DefaultAzureCredential());
return client;
}
You can register a service client for dependency injection in a .NET app.
You can also create client objects for specific containers or blobs. To learn more about creating and managing client objects, see Create and manage client objects that interact with data resources.
The authorization mechanism must have the necessary permissions to set a blob's access tier. For authorization with Microsoft Entra ID (recommended), you need Azure RBAC built-in role Storage Blob Data Contributor or higher. To learn more, see the authorization guidance for Set Blob Tier.
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, see Access 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, see Blob 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, see Set Blob Tier (REST API).
नोट
To set the access tier to Cold
using .NET, you must use a minimum client library version of 12.15.0.
You can set a blob's access tier on upload by using the BlobUploadOptions class. The following code example shows how to set the access tier when uploading a blob:
public static async Task UploadWithAccessTierAsync(
BlobContainerClient containerClient,
string localFilePath)
{
string fileName = Path.GetFileName(localFilePath);
BlockBlobClient blockBlobClient = containerClient.GetBlockBlobClient(fileName);
var uploadOptions = new BlobUploadOptions()
{
AccessTier = AccessTier.Cool
};
FileStream fileStream = File.OpenRead(localFilePath);
await blockBlobClient.UploadAsync(fileStream, uploadOptions);
fileStream.Close();
}
To learn more about uploading a blob with .NET, see Upload a blob with .NET.
You can change the access tier of an existing block blob by using one of the following functions:
The following code example shows how to change the access tier for an existing blob to Cool
:
public static async Task ChangeBlobAccessTierAsync(
BlobClient blobClient)
{
// Change the access tier of the blob to cool
await blobClient.SetAccessTierAsync(AccessTier.Cool);
}
If you are rehydrating an archived blob, you can optionally set the rehydratePriority
parameter to High
or Standard
.
You can change the access tier of an existing block blob by specifying an access tier as part of a copy operation. To change the access tier during a copy operation, use the BlobCopyFromUriOptions class and specify the AccessTier property. If you're rehydrating a blob from the archive tier using a copy operation, you can optionally set the RehydratePriority property to High
or Standard
.
The following code example shows how to rehydrate an archived blob to the Hot
tier using a copy operation:
public static async Task RehydrateBlobUsingCopyAsync(
BlobClient sourceArchiveBlob,
BlobClient destinationRehydratedBlob)
{
// Note: the destination blob must have a different name than the archived source blob
// Configure copy options to specify hot tier and standard priority
BlobCopyFromUriOptions copyOptions = new()
{
AccessTier = AccessTier.Hot,
RehydratePriority = RehydratePriority.Standard
};
// Copy source blob from archive tier to destination blob in hot tier
CopyFromUriOperation copyOperation = await destinationRehydratedBlob
.StartCopyFromUriAsync(sourceArchiveBlob.Uri, copyOptions);
await copyOperation.WaitForCompletionAsync();
}
To learn more about copying a blob with .NET, see Copy a blob with .NET.
To learn more about setting access tiers using the Azure Blob Storage client library for .NET, see the following resources.
The Azure SDK for .NET contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar .NET paradigms. The client library methods for setting access tiers use the following REST API operation:
ईवेंट्स
31 मार्च, 11 pm - 2 अप्रैल, 11 pm
सबसे बड़ा फैब्रिक, Power BI और SQL सीखने का इवेंट। मार्च 31 - अप्रैल 2। $ 400 बचाने के लिए कोड FABINSIDER का उपयोग करें।
आज पंजीकरण करेंप्रशिक्षण
मॉड्यूल
Azure ब्लॉब संग्रहण जीवनचक्र प्रबंधित करें - Training
Azure ब्लॉब संग्रहण जीवनचक्र में डेटा उपलब्धता प्रबंधित करने का तरीका जानें.
Certification
Microsoft प्रमाणित: Azure डेवलपर सहयोगी - Certifications
Azure फ़ंक्शन बनाने, वेब ऐप्स को लागू करने और प्रबंधित करने, Azure संग्रहण का उपयोग करके समाधान विकसित करने, और बहुत कुछ करने के लिए Microsoft Azure में एंड-टू-एंड समाधान बनाएँ।