<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chandra Mohan Jha</title>
    <description>The latest articles on DEV Community by Chandra Mohan Jha (@imcmjha).</description>
    <link>https://dev.to/imcmjha</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F602221%2Fa76e022e-fbbe-4c9f-bc35-58772e8abad7.png</url>
      <title>DEV Community: Chandra Mohan Jha</title>
      <link>https://dev.to/imcmjha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imcmjha"/>
    <language>en</language>
    <item>
      <title>Get blob from azure using Azure.Storage.Blobs</title>
      <dc:creator>Chandra Mohan Jha</dc:creator>
      <pubDate>Wed, 21 Jul 2021 07:27:07 +0000</pubDate>
      <link>https://dev.to/imcmjha/get-blob-from-azure-using-azure-storage-blobs-28lb</link>
      <guid>https://dev.to/imcmjha/get-blob-from-azure-using-azure-storage-blobs-28lb</guid>
      <description>&lt;p&gt;We can store blobs in Azure platform in C# using &lt;code&gt;Azure.Storage.Blobs&lt;/code&gt;. In this article, we will fetch the blobs without downloading as a file.&lt;/p&gt;

&lt;h2&gt;
  
  
  First thing first: install NuGet package
&lt;/h2&gt;

&lt;p&gt;Install NuGet package &lt;code&gt;Azure.Storage.Blobs&lt;/code&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Import library
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Azure.Storage.Blobs;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Get connection string
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const string CONN_STRING = &amp;lt;connection_string_from_azure_portal&amp;gt;
const string BLOB_CONTAINER = &amp;lt;blob_container_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Now the final thing
&lt;/h2&gt;

&lt;p&gt;We will fetch the blob and read it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string filePath = "&amp;lt;optional_path/file_name.extension&amp;gt;";
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
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. I hope it would be helpful to you. 🙂 &lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>azure</category>
      <category>storage</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Get all blobs in given Azure container</title>
      <dc:creator>Chandra Mohan Jha</dc:creator>
      <pubDate>Fri, 26 Mar 2021 12:49:12 +0000</pubDate>
      <link>https://dev.to/imcmjha/get-all-blobs-in-given-azure-container-aoe</link>
      <guid>https://dev.to/imcmjha/get-all-blobs-in-given-azure-container-aoe</guid>
      <description>&lt;p&gt;In last article, we tried to download single blob file from azure storage using &lt;code&gt;Azure.Storage.Blobs&lt;/code&gt;. This is the new library developed by &lt;code&gt;Microsoft&lt;/code&gt; to replace depercated &lt;code&gt;Microsoft.WindowsAzure.Storage&lt;/code&gt;. So let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  0. Setting up the context
&lt;/h2&gt;

&lt;p&gt;In this article, we will try to get all the blobs(images) stored on Azure blob storage in defined format i.e. &lt;code&gt;User_id/image.ext&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;john_doe/image1.jpg
john_doe/profile.png
jane_doe/profile.PNG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So if there are blobs with given name in Azue, we are trying to get all blobs for user id &lt;code&gt;john_doe&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Install NuGet package
&lt;/h2&gt;

&lt;p&gt;Install NuGet package &lt;code&gt;Azure.Storage.Blobs&lt;/code&gt;. At the time of writing this, the latest version is 12.8.0.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Import library
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;using Azure.Storage.Blobs;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Get connection string
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const string CONN_STRING = &amp;lt;connection_string_from_azure_portal&amp;gt;
const string BLOB_CONTAINER = &amp;lt;blob_container_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  -1. Now the final thing
&lt;/h2&gt;

&lt;p&gt;I will list all blobs(images) present in given container and have specified format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string userId = "john_doe";
var allBlobs = container.GetBlobs(prefix: $"{userId}");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will fetch all the blobs details present in container with given prefix(john_doe).&lt;/p&gt;

&lt;p&gt;If you want to download the blobs as well, &lt;a href="https://dev.to/imcmjha/download-blob-from-azure-using-azure-storage-blobs-c0m"&gt;this article&lt;/a&gt; might be helpful.&lt;/p&gt;

&lt;p&gt;That's it. I hope this will be helpful. 🙂 &lt;/p&gt;

</description>
      <category>csharp</category>
      <category>azure</category>
      <category>blob</category>
      <category>storage</category>
    </item>
    <item>
      <title>Download blob from azure using Azure.Storage.Blobs</title>
      <dc:creator>Chandra Mohan Jha</dc:creator>
      <pubDate>Tue, 23 Mar 2021 10:41:02 +0000</pubDate>
      <link>https://dev.to/imcmjha/download-blob-from-azure-using-azure-storage-blobs-c0m</link>
      <guid>https://dev.to/imcmjha/download-blob-from-azure-using-azure-storage-blobs-c0m</guid>
      <description>&lt;p&gt;We can store blobs in Azure platform in C# using &lt;code&gt;Azure.Storage.Blobs&lt;/code&gt;. Previously we had &lt;code&gt;Microsoft.WindowsAzure.Storage&lt;/code&gt; for this but they rewrote it. Don't ask me why. As &lt;code&gt;Microsoft.WindowsAzure.Storage&lt;/code&gt; is deprecated now and we needed to access Azure to read blobs, we have no other option rather than using new &lt;code&gt;Azure.Storage.Blobs&lt;/code&gt;. If you search docs to use Azure in C#, the results will be flooded with &lt;code&gt;Microsoft.WindowsAzure.Storage&lt;/code&gt;. If you ask specifically about new APIs, you will get mostly Microsoft docs links. I find Microsoft docs unusable🤭. And if you are like me, you are welcome to follow the article.&lt;/p&gt;

&lt;h2&gt;
  
  
  First thing first: install NuGet package
&lt;/h2&gt;

&lt;p&gt;Install NuGet package &lt;code&gt;Azure.Storage.Blobs&lt;/code&gt;. At the time of writing this, the latest version is 12.8.0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Import library
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;using Azure.Storage.Blobs;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Get connection string
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const string CONN_STRING = &amp;lt;connection_string_from_azure_portal&amp;gt;
const string BLOB_CONTAINER = &amp;lt;blob_container_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Now the final thing
&lt;/h2&gt;

&lt;p&gt;I will download the blob to a local file and read it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string filePath = "&amp;lt;optional_path/file_name.extension&amp;gt;";
var blobClient = new BlobClient(CONN_STRING, BLOB_CONTAINER, &amp;lt;blob_uri&amp;gt;);
var result =  blobClient.DownloadTo(filePath); // file is downloaded
// check file download was success or not
if (result.Status == 206 || result.Status == 200)
{
  // You would be knowing this by now
  using (StreamReader r = new StreamReader(filePath))
  {
    string content = r.ReadToEnd(); // I don't know what you want to do with this
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. I hope it would be helpful to you. 🙂 &lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>azure</category>
      <category>storage</category>
      <category>csharp</category>
    </item>
  </channel>
</rss>
