Hi Developers,
I was creating a
small demo to read and write few images into cloud blob storage, while coding I
faced this easy but interesting issue/error while calling
CreateIfNotExists() method of blob/queue/table client. Error screen shot shown
below. it says:
"An unhandled exception of type
'Microsoft.WindowsAzure.Storage.StorageException' occurred in
Microsoft.WindowsAzure.Storage.dll Additional information: The remote server
returned an error: (400) Bad Request."
While looking into
it inner exception, I do not see much help….
Below is my Code
snippet:
var blobClient = account.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(@"Images");
container.CreateIfNotExists();
var blob = container.GetBlockBlobReference(@"CompanyLogoUpload.jpg");
string inputblobname = @"D:\Junk\Logo_Uplaod.jpg";using (FileStream stream = new FileStream(inputblobname, FileMode.Open))
{
blob.UploadFromStream(stream);
}
Highlighted in RED
lines give above error….
Resolutions:
Error message is
misleading as it says "400-Bad Request", so we might go and verify
Azure Connectivity, are we connecting to right subscription, login credentials,
etc.. .
But the problem was,
I gave Container name which starts with Capital letter e.g. Images.
Azure does not allow capital letter in container name. I changes this to images,
and it worked.
When you create a
container from UI, error is very descriptive and you do not face this issue,
but this comes only when you create container from code behind.
Easy but good to
know !!!!
You can also refer
at https://msdn.microsoft.com/en-us/library/dd135715.aspx for more details.
Thanks a lot
ReplyDeleteThank you!
ReplyDeleteThnaks!!!
ReplyDeleteThere seems to be some other reason for this error. i have containername all in small case but still i see the same error. below is code snippet,
ReplyDeletecontainer creation throws same exception as mentioned in article above. Any help would be appreciated.
//create a container
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("imagecontainer");
//create a container if it is not already exists
if (cloudBlobContainer.CreateIfNotExists())
{
did you tried creating the same container from portal, do you see any error on portal? also drop me full code. this should be easy to solve.
ReplyDeleteHi Tushar, is it possible to automatically generate GetBlockBlobReference(string) for CloudBlockBlob?? I mean the string value must change for every new blob like we have a method named CreateIfNotExists() if there is no reference Because i have a looping to store a blob.
ReplyDeleteUnfortunatly No. Because every blob in Azure storage must reside in a container. The container forms part of the blob name. so while accessing you have to follow the same hierarchy account -> Containt -> Blob.
ReplyDeleteThanks!
ReplyDeleteExcellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.
ReplyDeleteAzure Online Course Bangalore
The Information Shared Is Very Valuable Please Keep Updating Us.
ReplyDeleteMS Azure Training in Hyderabad
MS Azure Training in Ameerpet
Microsoft Azure Training in Hyderabad
Azure Training
Azure Online Training
MS Azure Online Training
thankyou sharing this.
ReplyDeleteMicrosoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
ReplyDeleteawful piece of information, I had come to know about your blog from my friend vimal, mumbai,i have read atleast 3 posts of yours by now, and let me tell you, your blog gives the best and the most interesting information.
Microsoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
Good article. Very best to read. I really love to read such a nice article. Thanks!
ReplyDeleteFull Stack Training in Chennai | Certification | Online Training Course| Full Stack Training in Bangalore | Certification | Online Training Course | Full Stack Training in Hyderabad | Certification | Online Training Course | Full Stack Developer Training in Chennai | Mean Stack Developer Training in Chennai | Full Stack Training | Certification | Full Stack Online Training Course