C# Azure 将文件上传到 "File Storage Service"- 不是 Blob 存储

标签 c# azure

我需要将文件上传到Azure文件存储服务C#(不是Blob存储),我搜索了很多,但没有找到如何操作,只找到了如何执行此操作的信息对于 Blob 存储,似乎不支持它或者我搜索不好。

我可以到达这里,但是没有像 blob 中那样的 UploadFromStream() 方法

FileInfo file = new FileInfo(@"C:\...\file.txt");
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference(ConfigurationManager.AppSettings["ShareReference"]);
CloudFileDirectory root = share.GetRootDirectoryReference();
CloudFileDirectory dir = root.GetDirectoryReference("TESTDIR");

using (FileStream fs = file.OpenRead())
{
    // what should I do here
}

可以这样上传文件吗?
在这种情况下我错过了什么?

最佳答案

您需要首先为要从 CloudFileDirectory 实例创建的文件创建一个 CloudFile 实例。获得引用后,您可以通过多种方式上传它,包括 CloudFile.UploadFromStream() 方法。

FileInfo file = new FileInfo(@"C:\...\file.txt");
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference(ConfigurationManager.AppSettings["ShareReference"]);
CloudFileDirectory root = share.GetRootDirectoryReference();
CloudFileDirectory dir = root.GetDirectoryReference("TESTDIR");

var cloudFile = dir.GetFileReference("myfile.txt");

using (FileStream fs = file.OpenRead())
{
    cloudFile.UploadFromStream(fs);
}

关于C# Azure 将文件上传到 "File Storage Service"- 不是 Blob 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37887461/

相关文章:

c# - ASP.NET MVC 对象引用未设置为对象的实例

c# - TcpClient.Close() 仅适用于 Thread.Sleep()

c# - 在具有 2 个属性的 LINQ 中分组

c# - 图 Api - 401 未经授权

json - 使用 Azure Web 作业将数据导入到 Azure SQL

c# - 如何将数组的内容写入文本文件? C#

c# - Concat HashSet<String> 和 IList<String>

azure - Windows Azure 帐户的多个管理员

azure - 使用TFS构建服务器但不部署

azure - ApplicationInsights 中保留的 EventId