Skip to content

Instantly share code, notes, and snippets.

@mikecole
Last active October 5, 2021 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikecole/e09de696766e6a3e16cc0017d0136936 to your computer and use it in GitHub Desktop.
Save mikecole/e09de696766e6a3e16cc0017d0136936 to your computer and use it in GitHub Desktop.
Upload a file to Azure Blob Stage
public async Task CreateBlobAsync(string connectionString, string containerName, string blobName, string content, string contentType = null)
{
var container = new BlobContainerClient(connectionString, containerName);
await container.CreateIfNotExistsAsync();
var blob = container.GetBlobClient(blobName);
await blob.DeleteIfExistsAsync();
using var stream = new MemoryStream(Encoding.Default.GetBytes(content), false);
var headers = new BlobHttpHeaders();
if (!string.IsNullOrWhiteSpace(contentType))
{
headers.ContentType = contentType;
}
await blob.UploadAsync(stream, headers);
}
@mikecole
Copy link
Author

mikecole commented Oct 5, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment