Blob Properties
Understanding the properties associated with a blob is crucial for managing its data, access, and lifecycle within Azure Blob Storage. This document details the various properties you can configure and retrieve for a blob.
Blob Metadata
Metadata is a collection of key-value pairs that you can associate with a blob. It's useful for storing custom information about the blob, such as author, creation date, or any other context relevant to your application. Metadata is not used by Azure Storage itself but is returned with blob requests.
- Metadata keys and values are case-insensitive.
- Keys must conform to naming restrictions: start with a letter or number, can contain letters, numbers, hyphens, underscores, and periods.
- Keys and values are limited in length.
Blob System Properties
These properties are managed by Azure Storage and provide information about the blob's state and characteristics:
- ETag: An identifier for the version of the blob. Used for optimistic concurrency.
- Last-Modified: The date and time the blob was last modified.
- Content-Length: The size of the blob in bytes.
- Content-Type: The MIME type of the blob (e.g.,
image/jpeg,application/json). - Content-Encoding: The encoding of the blob content.
- Content-Language: The language of the blob content.
- Cache-Control: Specifies directives for caching mechanisms.
- Content-Disposition: Provides a
Content-Dispositionheader value.
Blob Access Tier
Blob storage offers different access tiers to optimize costs based on data access patterns:
- Hot: Optimized for frequently accessed data. Higher storage costs, lower access costs.
- Cool: Optimized for infrequently accessed data. Lower storage costs, higher access costs. Stored for at least 30 days.
- Archive: Optimized for rarely accessed data. Lowest storage costs, highest access costs. Data retrieval can take hours. Stored for at least 180 days.
You can set or change the access tier of a blob at any time.
Blob Tags
Blob tags are key-value pairs that are indexed and queryable. They can be used for cost analysis, reporting, or managing access control policies based on tags. Tags are case-sensitive.
- Tags can be applied to blobs and containers.
- They can be used in Azure policies and RBAC assignments.
Accessing Blob Properties via SDK (Example: .NET)
You can retrieve blob properties using the Azure Storage SDKs. Here's a C# example:
using Azure.Storage.Blobs;
using System;
// ...
string connectionString = "YOUR_CONNECTION_STRING";
string containerName = "mycontainer";
string blobName = "myblob.txt";
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobClient(containerName);
BlobClient blobClient = containerClient.GetBlobClient(blobName);
try
{
Azure.Response<BlobProperties> propertiesResponse = await blobClient.GetPropertiesAsync();
BlobProperties properties = propertiesResponse.Value;
Console.WriteLine($"Blob Name: {blobName}");
Console.WriteLine($"Content Type: {properties.ContentType}");
Console.WriteLine($"Content Length: {properties.ContentLength} bytes");
Console.WriteLine($"Last Modified: {properties.LastModified}");
Console.WriteLine($"ETag: {properties.ETag}");
Console.WriteLine($"Access Tier: {properties.AccessTier}");
foreach (var tag in properties.Tags)
{
Console.WriteLine($"Tag: {tag.Key} = {tag.Value}");
}
foreach (var metadataEntry in properties.Metadata)
{
Console.WriteLine($"Metadata: {metadataEntry.Key} = {metadataEntry.Value}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error retrieving blob properties: {ex.Message}");
}
Accessing Blob Properties via REST API
You can retrieve blob properties using the Get Blob Properties REST API operation. This operation returns a set of HTTP headers that include the blob's properties.
Request:
GET /<container-name>/<blob-name>?comp=properties HTTP/1.1
Host: <storage-account-name>.blob.core.windows.net
x-ms-version: 2020-08-04
Authorization: SharedKey <storage-account-name>:<signature>
Response Headers (Partial Example):
HTTP/1.1 200 OK
Content-Length: 0
Last-Modified: Tue, 25 Aug 2023 22:38:02 GMT
ETag: "0x8D546329C50A7C5"
x-ms-blob-type: BlockBlob
x-ms-access-tier: Hot
x-ms-server-encrypted: true
x-ms-lease-status: unlocked
x-ms-blob-committed-block-count: 0
x-ms-tag-header: Environment=Production&Project=AzureDocs
x-ms-blob-content-type: application/octet-stream
x-ms-blob-content-length: 102400
x-ms-blob-content-md5: null
x-ms-blob-content-encoding: null
x-ms-blob-content-language: null
x-ms-blob-cache-control: null
x-ms-blob-content-disposition: null
x-ms-copy-completion-time: null
x-ms-copy-status-description: null
x-ms-copy-status: pending
x-ms-copy-source: null
Date: Wed, 26 Aug 2023 10:00:00 GMT
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
Managing Blob Properties
Blob properties can be managed in several ways:
- During Upload: Many properties like
Content-Type,Content-Encoding, and metadata can be set when a blob is first uploaded. - Via SDKs: Use the Azure Storage SDKs to modify properties, change access tiers, or update tags on existing blobs.
- Via REST API: Programmatically interact with blob properties using REST API calls.
- Azure Portal: The Azure portal provides a user-friendly interface to view and modify blob properties.