gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:59:16 26 4
gpt4 key购买 nike

我查看了以下链接以将字符串上传到 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com