Blob Service REST API
The Azure Blob Storage REST API provides a programmatic interface for interacting with Azure Blob Storage. You can use this API to manage containers and blobs within your storage account.
Introduction to the Blob Service REST API
The Blob service exposes the following resources:
- Storage Account: The top-level resource.
- Containers: Collections of blobs. Containers are created within a storage account.
- Blobs: Individual files or pieces of data stored in a container. There are three types of blobs: block blobs, append blobs, and page blobs.
All Blob service operations are RESTful operations that are invoked using standard HTTP methods (GET, PUT, POST, HEAD, DELETE). The Blob service operations are categorized as follows:
- Account Operations: Operations on the storage account.
- Container Operations: Operations on containers.
- Blob Operations: Operations on blobs.
Account Operations
List Containers
GET /{accountName}/containersRetrieves a list of all containers within the specified storage account.
Query Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
comp |
String | Yes | Must be set to list. |
prefix |
String | No | Filters containers by a specified prefix. |
maxresults |
Integer | No | Specifies the maximum number of containers to return. |
Get Account Properties
GET /{accountName}Retrieves the properties of the specified storage account.
Query Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
comp |
String | Yes | Must be set to properties. |
Container Operations
Create Container
PUT /{accountName}/{containerName}Creates a new container within the specified storage account.
Request Headers:
| Name | Type | Required | Description |
|---|---|---|---|
x-ms-blob-public-access |
String | No | Specifies the public access level for the container (e.g., blob, container, off). |
x-ms-meta-name |
String | No | User-defined metadata for the container. |
List Blobs
GET /{accountName}/{containerName}/blobsRetrieves a list of all blobs within the specified container.
Query Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
restype |
String | Yes | Must be set to container. |
comp |
String | Yes | Must be set to list. |
prefix |
String | No | Filters blobs by a specified prefix. |
maxresults |
Integer | No | Specifies the maximum number of blobs to return. |
Delete Container
DELETE /{accountName}/{containerName}Deletes the specified container and all of its contents.
Blob Operations
Upload Blob (Block Blob)
PUT /{accountName}/{containerName}/{blobName}Uploads a new block blob or overwrites an existing one.
Request Headers:
| Name | Type | Required | Description |
|---|---|---|---|
x-ms-blob-type |
String | Yes | Must be set to BlockBlob. |
Content-Length |
Integer | Yes | The size of the blob data in bytes. |
x-ms-meta-name |
String | No | User-defined metadata for the blob. |
Download Blob
GET /{accountName}/{containerName}/{blobName}Downloads a blob from the specified container.
Query Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
snapshot |
DateTime | No | Specifies a snapshot version of the blob to download. |
Delete Blob
DELETE /{accountName}/{containerName}/{blobName}Deletes the specified blob.
Query Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
snapshot |
DateTime | No | Specifies a snapshot version of the blob to delete. |
Authentication
All Azure Storage REST API requests must be authenticated. The primary methods for authentication are:
- Shared Key Authorization: Using the account name and one of the account access keys.
- Shared Access Signatures (SAS): Delegating access to resources without sharing the account key.
- Azure Active Directory (Azure AD): Using service principals or managed identities for authorized access.
Refer to the Storage Authentication overview for detailed information.
Request and Response Headers
Various headers are used to control the behavior of operations and provide information about the resources. Common headers include:
Content-TypeContent-Lengthx-ms-dateAuthorizationx-ms-versionETagLast-Modified
Error Handling
Azure Storage returns standard HTTP status codes to indicate the success or failure of a request. Error details are typically provided in the response body in XML or JSON format.
HTTP/1.1 404 The specified container does not exist.
Content-Type: application/xml
...
<Error>
<Code>ContainerNotFound</Code>
<Message>The specified container does not exist.
RequestId:8c521916-f00e-4309-8395-62109460245b
Time:2023-10-27T10:00:00.0000000Z</Message>
</Error>
For a comprehensive list of operations, parameters, and response details, please refer to the official Microsoft Azure Storage REST API documentation.