proteus
proteus

Reputation: 555

credentials for CloudStorageAccount using DevelopmentStorage

I'm developing a webjob to put items in a queue (C#). I'm new to this and I'm following some tutorials, but I can't figure out how I would create an instance of a CloudStorageAccount for my local development storage. In my config file, I have this

<add name="AzureWebJobsStorage" connectionString="UseDevelopmentStorage=true;" />

and In my C# method, I want to create an instance of my CloudStorageAccount, like this

var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);

what should accountName and accountKey be for local development storage?

Upvotes: 3

Views: 2530

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136196

what should accountName and accountKey be for local development storage ?

Account name: devstoreaccount1
Account key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

Ref: https://learn.microsoft.com/en-us/azure/storage/storage-use-emulator

However you will not be able to use the code below as storage emulator only works on HTTP and listens on custom ports.

var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);

Correct way to do would be to something like below:

        var storageCredentials = new StorageCredentials("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");
        var blobEndpoint = new Uri("http://127.0.0.1:10000");
        var queueEndpoint = new Uri("http://127.0.0.1:10001");
        var tableEndpoint = new Uri("http://127.0.0.1:10002");
        var acc = new CloudStorageAccount(storageCredentials, blobEndpoint, queueEndpoint, tableEndpoint, null);

or for simplicity, you could simply do:

        var acc = CloudStorageAccount.Parse("UseDevelopmentStorage=true");

Upvotes: 7

Related Questions