santhoshi sirangi
santhoshi sirangi

Reputation: 21

Azure SAS connection is not working with Azure.Storage.Blobs

I am using Azure.Storage.Blobs, Version=12.1.0.0. Blobclient is working fine with AccessKey ,but we wanted to use SAS connectionstring It is throwing exception here.

var blobClient = new BlobServiceClient(**Connectionstring**);

"No valid combination of account information found." this is the exception am getting at the above line.

I am using the below SAS connection format BlobEndpoint=xxxxxxx;QueueEndpoint=xxxxxxx;FileEndpoint=xxxxxxx;TableEndpoint=xxxxxxx;SharedAccessSignature=xxxxxxx

Upvotes: 2

Views: 587

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 30035

For SAS connection, you should follow the steps below to generate sas-url: Nav to azure portal -> your storage account -> Shared access signature:

enter image description here

Then copy the "Blob Service SAS URL"(if you want to operate file share / queue, you should use the respective SAS URL).

Then in the code with library Azure.Storage.Blobs, Version=12.1.0.0.:

using Azure.Storage.Blobs;
using System;

namespace ConsoleApp16
{
    class Program
    {
        static void Main(string[] args)
        {
            //replace the sas_url with the one you copied in the above steps.
            string sas_url = "https://xxx.blob.core.windows.net/?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2020-01-07T17:04:27Z&st=2020-01-07T09:04:27Z&spr=https&sig=xxx";
            Uri uri = new Uri(sas_url);
            BlobServiceClient blobServiceClient = new BlobServiceClient(uri);

            var blobContainer = blobServiceClient.GetBlobContainerClient("test1");

            var blobclient = blobContainer.GetBlobClient("yy1.txt");
            blobclient.Upload(@"d:\aa.txt");


            Console.WriteLine("**completed**");
            Console.ReadLine();
        }
    }
}

Upvotes: 4

Related Questions