问题
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