コード例 #1
0
        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));
        }
コード例 #2
0
 private static string AbsoluteAccessPath(IAzureBlobFileStorageConfig config, string relativePathAndFileName)
 {
     return($"https://{config.AccountName}.blob.{config.EndpointSuffix}/{config.Container}/{relativePathAndFileName}");
 }
コード例 #3
0
 public AzureBlobFileStorage(IAzureBlobFileStorageConfig config)
 {
     _config = config;
     Logger  = NullLogger.Instance;
 }
コード例 #4
0
        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));
        }