Error in uploading blob in Azure storage account

0

I'm using below code to create Azure container.

    string cs = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"];
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(cs);
   blobClient = storageAccount.CreateCloudBlobClient();        
    CloudBlobContainer con1 = CreateContainer("container1", false);

But I am getting following error while creating Container in Azure:

Microsoft.WindowsAzure.Storage.StorageException
  HResult=0x80131500
  Message=The remote server returned an error: (400) Bad Request.
  Source=Microsoft.WindowsAzure.Storage

Note: I have followed Azure naming conventions for creating containers. All are in lower case letters but still getting error. Please suggest next steps.

azure-devops
azure-storage-blobs
azure-storage-account
asked on Stack Overflow Apr 19, 2021 by Pardha • edited Apr 19, 2021 by BKN

2 Answers

0

I believe that the package you are using is deprecated (WindowsAzure.Storage).

You may try to use the newest Azure.Storage.Blobs. The code sample you need seems to be this: Create a container :)

Despite the suggestion, in which instruction are you getting the error? If you can, please provide more details, since the application of the suggested example may or may not solve your problem.

answered on Stack Overflow Apr 19, 2021 by N Pinheiro • edited Apr 19, 2021 by N Pinheiro
0

Update:

Below code works fine on my side(I use the package that your error shows):

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Threading.Tasks;

namespace ConsoleApp55
{
    class Program
    {
        static async Task Main(string[] args)
        {
            string cs = "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(cs);
            var blobclient= storageAccount.CreateCloudBlobClient();
            CloudBlobContainer con1 = blobclient.GetContainerReference("test0419");
            await con1.CreateAsync();
            Console.WriteLine("Hello World!");
        }
    }
}

enter image description here

If still don't work, please show more details.

Original Answer:

From your error, it seems you are using old package reference.

The newest package reference tutorials is here:

https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-dotnet#code-examples

And please make sure you didn't create the container before.

answered on Stack Overflow Apr 19, 2021 by Bowman Zhu • edited Apr 19, 2021 by Bowman Zhu

User contributions licensed under CC BY-SA 3.0