【发布时间】:2020-11-07 02:15:14
【问题描述】:
我有以下指向 .Net Core 2.1 的控制台应用程序,它执行从 blob 读取和写入的简单操作。 我在这里用 * 隐藏了帐户密钥。但是连接正常。
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Blob;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string connectionString = $"DefaultEndpointsProtocol=https;AccountName=r53eripcjroswtest;AccountKey=***;";
// Setup the connection to the storage accounts
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
// Connect to the blob storage
CloudBlobClient serviceClient = storageAccount.CreateCloudBlobClient();
// Connect to the blob container
CloudBlobContainer container = serviceClient.GetContainerReference("igb-test");
CloudBlockBlob blob = container.GetBlockBlobReference("Test.txt");
string contents = blob.DownloadTextAsync().Result;
//blob.UploadTextAsync("This is coming from the Program");
}
}
}
我已经运行了上面的代码,并且能够在“contents”变量中读取文件的内容。 但是当我尝试写入文件时(在取消注释 ---blob.UploadTextAsync("This iscoming from the Program")--line 并注释读取行之后),没有任何内容被写入文件。
注意:文本文件开头为空。首先我尝试通过我的控制台程序写入文件,然后没有发生任何事情然后打开文件并手动写入并能够读取其内容。
当我尝试通过 azure 函数运行相同的代码并将其发布到 azure 门户时,它能够读取/写入文件。
我的问题是我们不能使用 .exe(控制台应用程序)在 azure 中写入 blob?只有通过功能应用程序才能做到? 谁能指导我这里哪里出错了。
【问题讨论】:
标签: c# azure azure-functions console-application azure-blob-storage