Currently, in our application, all blob storage and containers have public access. But, regarding security purposes, we are going to make containers and blobs private. After making the private, we are getting a 404 error status code while reading a file from blob.
We know there are multiple ways to access a private blob using C#. But we don't want to go with the SaS token.
Except for the SAS token, is there any other way to access private blobs in the web API in C#?


Amit MohantyRank #112 · 20K reputationPosted May 25, 2023, 8:26 AM EDT
In that case, if you want to display the private blob on the UI without using a SAS token, you can create a server-side endpoint that serves as a proxy to retrieve the blob content and return it to the client.
Amit MohantyRank #112 · 20K reputationPosted May 23, 2023, 5:46 AM EDT
Yes, besides using a SAS (Shared Access Signature) token, there is another way to access private blobs in a web API using C#: by making use of the Azure Storage account key.
using Microsoft.Azure.Storage; using Microsoft.Azure.Storage.Auth; using Microsoft.Azure.Storage.Blob; public static async Task ReadPrivateBlobAsync() { // Set up the storage account and blob client string accountName = "your_storage_account_name"; string accountKey = "your_storage_account_key"; string containerName = "your_container_name"; string blobName = "your_blob_name"; StorageCredentials storageCredentials = new StorageCredentials(accountName, accountKey); CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(containerName); CloudBlockBlob blob = container.GetBlockBlobReference(blobName); // Read the blob content using (var memoryStream = new MemoryStream()) { await blob.DownloadToStreamAsync(memoryStream); byte[] blobContent = memoryStream.ToArray(); // Process the blob content as needed } }Atul PatilRank #2,535 · 552 reputationPosted May 25, 2023, 7:25 AM EDT
Thanks for the response Amit, but the requirement is we have stored the blob storage path into the DB, and returning that path from DB. Using that path we are showing image on UI.
When we make a Private access, that path gives an error 404 on UI.