[英]Upload string to Azure Blob
I have had a look at this following link to upload a string to azure blob.我查看了以下链接以将字符串上传到 azure blob。 my task requirement does not allow me to store the string as a file.我的任务要求不允许我将字符串存储为文件。
Is there any way of writing file to Azure Blob Storage directly from C# application? 有没有办法直接从 C# 应用程序将文件写入 Azure Blob 存储?
It is using CloudStorageAccount in WindowsAzure.Storage which is deprecated already as per this link它在 WindowsAzure.Storage 中使用 CloudStorageAccount,根据此链接已弃用
I am trying to use Azure.Storage.Blobs library.我正在尝试使用 Azure.Storage.Blobs 库。 HOwever, there's no longer UploadString method as per this microsoft documentation然而,根据这个微软文档,不再有 UploadString 方法
any advices?有什么建议吗? thanks谢谢
You can upload a stream, so you can get the content of your string as a byte array, create a memory stream and upload it.您可以上传流,因此您可以将字符串的内容作为字节数组获取,创建内存流并上传。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.