private static CloudBlobContainer GetCloudBlobContainer(IAzureBlobFileStorageConfig storageConfig) { // Create storagecredentials object by reading the values from the configuration (appsettings.json) StorageCredentials storageCredentials = new StorageCredentials(storageConfig.AccountName, storageConfig.AccountKey); // Create cloudstorage account by passing the storagecredentials CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, storageConfig.EndpointSuffix, true); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Get reference to the blob container by passing the name by reading the value from the configuration (appsettings.json) return(blobClient.GetContainerReference(storageConfig.Container)); }
private static string AbsoluteAccessPath(IAzureBlobFileStorageConfig config, string relativePathAndFileName) { return($"https://{config.AccountName}.blob.{config.EndpointSuffix}/{config.Container}/{relativePathAndFileName}"); }
public AzureBlobFileStorage(IAzureBlobFileStorageConfig config) { _config = config; Logger = NullLogger.Instance; }
private static async Task <bool> UploadFileToStorage(Stream fileStream, string fileName, IAzureBlobFileStorageConfig _storageConfig) { var container = GetCloudBlobContainer(_storageConfig); // Get the reference to the block blob from the container CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName); // Upload the file await blockBlob.UploadFromStreamAsync(fileStream); return(await Task.FromResult(true)); }