getting 404 error when connecting to azure storage account

依然范特西╮ 提交于 2019-12-12 14:07:25

问题


I am going through the tutorial for blobs with azure storage accounts found here Azure Storage Tutorial

I have created the storage account on azure and it says it is up. I have copied the key and account name to my config file. I have verified the endpoint address in my application matches the one on my azure storage account. but when I run the code I get a 404 error. And when I copy and past the endpoint address from my azure account into a browser I also get a 404 error

here I the code. actually copied from the tutorial I did add the correct account name and key to the config string but removed them for this post

    // Retrieve storage account from connection string.
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Retrieve reference to a previously created container.
        CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

        // Retrieve reference to a blob named "myblob".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

        // Create or overwrite the "myblob" blob with contents from a local file.
        using (var fileStream = System.IO.File.OpenRead(@"myfile"))
        {
            blockBlob.UploadFromStream(fileStream);
        }

and the connection string

<appSettings>
    <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myAccount;AccountKey=mykey" />
</appSettings>

Any ideas why? Do I need to do something more in Azure?


回答1:


The problem was the container was not created or had been deleted. I added

container.CreateIfNotExist();

and it worked fine. I would have expect a different error not a 404. but that fixed it.



来源:https://stackoverflow.com/questions/18090859/getting-404-error-when-connecting-to-azure-storage-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!