Created
April 6, 2022 09:21
-
-
Save LucGosso/8671e01f0ced2fa189d7ee95a12586e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Azure.Storage.Blobs; | |
public string UploadJsonToAzureBlobStorage(string json) | |
{ | |
// Name of the share, directory, and file | |
string shareName = ConfigurationManager.AppSettings.Get("inRiver.StorageAccountShareReference"); | |
string storageAccountName = ConfigurationManager.AppSettings.Get("inRiver.StorageAccountName"); | |
string storageAccountKey = ConfigurationManager.AppSettings.Get("inRiver.StorageAccountKey"); | |
//Create a unique name for the container | |
string containerName = "datafeedwatch"; | |
string fileName = "items.json"; | |
string connectionString = $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey};EndpointSuffix=core.windows.net"; | |
// Create a BlobServiceClient object which will be used to create a container client | |
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString); | |
// Create the container and return a container client object | |
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName); | |
containerClient.CreateIfNotExists(); | |
// Get a reference to our file | |
BlobClient file = containerClient.GetBlobClient(fileName); | |
file.DeleteIfExists(); | |
// upload the file | |
byte[] bytes = Encoding.ASCII.GetBytes(json); | |
using (MemoryStream stream = new MemoryStream(bytes)) | |
{ | |
file.Upload(stream); | |
} | |
return file.Uri.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment