Is there any way of writing file to Azure Blob Storage directly from C# application?

元气小坏坏 提交于 2021-01-21 10:36:27

问题


I am trying to create a new C# console application that writes into the blob storage directly from the code. I am able to create a local file and upload it to the blob. But the requirement is writing the content directly to blob instead of creating a file and uploading to Blob.I am not being able to achieve this. I searched for the related web resources but couldn't find anything that would help in this issue. I am looking for suggestions/help.


回答1:


It's actually pretty straight forward. See the code below:

    static void SaveTextAsBlob()
    {
        var storageAccount = CloudStorageAccount.Parse("storage-account-connection-string");
        var blobClient = storageAccount.CreateCloudBlobClient();
        var container = blobClient.GetContainerReference("container-name");
        var blob = container.GetBlockBlobReference("blob-name.csv");
        blob.Properties.ContentType = "text/csv";
        string blobContents = GetCsvTextSomehow();
        blob.UploadText(blobContents);
    }


来源:https://stackoverflow.com/questions/56220364/is-there-any-way-of-writing-file-to-azure-blob-storage-directly-from-c-sharp-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!