c# - 将字符串上传到 Azure Blob

标签 c# .net-core azure-blob-storage

我查看了以下链接以将字符串上传到 azure blob。我的任务要求不允许我将字符串存储为文件。
Is there any way of writing file to Azure Blob Storage directly from C# application?
它在 WindowsAzure.Storage 中使用 CloudStorageAccount,根据 this link 已弃用。
我正在尝试使用 Azure.Storage.Blobs 库。然而,按照 this microsoft documentation 不再有 UploadString 方法
有什么建议吗?谢谢

最佳答案

您可以上传流,因此您可以将字符串的内容作为字节数组获取,创建内存流并上传。

BlobContainerClient container = new BlobContainerClient(connectionString, "myContainer");
container.Create();

BlobClient blob = container.GetBlobClient("myString");

var myStr = "Hello!"
var content = Encoding.UTF8.GetBytes(myStr);
using(var ms = new MemoryStream(content))
    blob.Upload(ms);

关于c# - 将字符串上传到 Azure Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64546110/

相关文章:

azure - 寻求 Blob 存储版本

c# - 如何将对象的类型与泛型类型进行比较,与泛型参数无关?

c# - 我需要做什么才能让我的 ASP.NET MasterPage 在我的服务器上运行?

c# - Asp.net MVC 多用户 session /用户模拟

c# - 共享启动配置 dotnet core 2 WebAPI

visual-studio - 使用.Net Core时,已安装的Nuget程序包所在的程序集在哪里?

c# - 如何检查 Azure Blob 文件是否存在

添加或修改 Blob 时 Azure 逻辑应用运行触发器

c# - 我的 linq select 不工作,我的 foreach 不工作

.net-core - 将 dotnetcore 5 web api 部署到 iis 给出 404