3

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?

4

1 回答 1

5

问题是容器未创建或已被删除。我添加了

container.CreateIfNotExist();

它工作得很好。我会期待一个不同的错误而不是 404。但它修复了它。

于 2013-08-07T20:17:37.143 回答