Skip to content

Latest commit

 

History

History
118 lines (98 loc) · 4.89 KB

File metadata and controls

118 lines (98 loc) · 4.89 KB

Azure Storage Blobs client library for .NET

Server Version: 2018-11-09

Azure Blob storage is Microsoft's object storage solution for the cloud. Blob storage is optimized for storing massive amounts of unstructured data. Unstructured data is data that does not adhere to a particular data model or definition, such as text or binary data.

Source code | Package (NuGet) | API reference documentation | Product documentation

Getting started

Install the package

Install the Azure Storage Blobs client library for .NET with NuGet:

Install-Package Azure.Storage.Blobs

Prerequisites: You must have an Azure subscription, and a Storage Account to use this package.

To create a Storage Account, you can use the Azure Portal, Azure PowerShell or Azure CLI:

Key concepts

Blob storage is designed for:

  • Serving images or documents directly to a browser.
  • Storing files for distributed access.
  • Streaming video and audio.
  • Writing to log files.
  • Storing data for backup and restore, disaster recovery, and archiving.
  • Storing data for analysis by an on-premises or Azure-hosted service.

Examples

Uploading a blob

string connectionString = <connection_string>;
var service = new BlobServiceClient(connectionString);
var container = service.GetBlobContainerClient("mycontainer");
await container.CreateAsync();

var blob = container.GetBlockBlobClient("myblob");
using (var data = File.OpenRead("Samples/SampleSource.txt"))
{
    await blob.UploadAsync(data);
}

Downloading a blob

string connectionString = <connection_string>;
var service = new BlobServiceClient(connectionString);
var container = service.GetBlobContainerClient("mycontainer");
var blob = container.GetBlockBlobClient("myblob");

var download = await blob.DownloadAsync();
using (var file = File.Create("BlockDestination.txt"))
{   
    await download.Value.Content.CopyToAsync(file);
}

Enumerating blobs

string connectionString = <connection_string>;
var service = new BlobServiceClient(connectionString);
var container = service.GetBlobContainerClient("mycontainer");

string marker;
do
{
    var response = await container.ListBlobsFlatSegmentAsync(marker);
    foreach (var blob in response.Value.BlobItems)
    {
        Console.WriteLine(blob.Name);
    }
    marker = response.Value.NextMarker;
}
while (!string.IsNullOrEmpty(marker));

Troubleshooting

All Blob service operations will throw a StorageRequestFailedException on failure with helpful ErrorCodes.

Next steps

Get started with our Blob samples.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Impressions