azure blob存储出现错误-指定的资源不存在

use*_*018 1 c# azure-blob-storage

我有一个蔚蓝的Blob存储容器网址,我正在尝试上传文件

这是代码,

try
        {
            string blobContainerUri = "https://upload.blob.core.windows.net/381a9218-cd78-4dc1-b9a2-f1ff4f952b57";
            CloudBlobContainer blobContainer = new CloudBlobContainer(new Uri(blobContainerUri));
            CloudBlockBlob blob = blobContainer.GetBlockBlobReference("sample.txt");
            string sampleContent = "This is sample text.";
            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(sampleContent)))
            {
                blob.UploadFromStream(ms);
            }
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            Console.WriteLine(ex.StackTrace.ToString());
        }
Run Code Online (Sandbox Code Playgroud)

现在我遇到错误,我是否需要同时使用存储帐户访问密钥或将其使用?

try
        {
            string blobContainerUri = "https://upload.blob.core.windows.net/381a9218-cd78-4dc1-b9a2-f1ff4f952b57";
            CloudBlobContainer blobContainer = new CloudBlobContainer(new Uri(blobContainerUri));
            CloudBlockBlob blob = blobContainer.GetBlockBlobReference("sample.txt");
            string sampleContent = "This is sample text.";
            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(sampleContent)))
            {
                blob.UploadFromStream(ms);
            }
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            Console.WriteLine(ex.StackTrace.ToString());
        }
Run Code Online (Sandbox Code Playgroud)

Md.*_*lim 5

您应该使用CloudBlobContainer实例修改代码。像

var uri = new Uri("https://upload.blob.core.windows.net/381a9218-cd78-4dc1-b9a2-f1ff4f952b57")
var storage = new StorageCredentials("your account name", "your storage key");

CloudBlobContainer blobContainer = new CloudBlobContainer(uri, storage);
Run Code Online (Sandbox Code Playgroud)

我希望它能起作用。