DEV Community

Chandra Mohan Jha
Chandra Mohan Jha

Posted on

3 1

Get blob from azure using Azure.Storage.Blobs

We can store blobs in Azure platform in C# using Azure.Storage.Blobs. In this article, we will fetch the blobs without downloading as a file.

First thing first: install NuGet package

Install NuGet package Azure.Storage.Blobs.

Import library

using Azure.Storage.Blobs;
Enter fullscreen mode Exit fullscreen mode

Get connection string

I assume you have Azure account and thus connection string to connect to Azure Blob Storage. Store this in a variable or constant based on your need.

const string CONN_STRING = <connection_string_from_azure_portal>
const string BLOB_CONTAINER = <blob_container_name>
Enter fullscreen mode Exit fullscreen mode

Now the final thing

We will fetch the blob and read it.

string filePath = "<optional_path/file_name.extension>";
var blobClient = new BlobClient(CONN_STRING, BLOB_CONTAINER, filePath);
using (var result = await blobClient.OpenReadAsync())
{
  byte[] content = new byte[result.Length];
  result.Read(content, 0, (int)result.Length);
  var jsonContent = System.Text.Encoding.Default.GetString(content);
  // Do whatever you want to do with this content
}
Enter fullscreen mode Exit fullscreen mode

That's it. I hope it would be helpful to you. 🙂

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay