Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions AdminUI/LearningHub.Nhs.AdminUI/Services/MKIOMediaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,21 @@ public async Task<string> CreateMediaInputAsset(IFormFile file)
/// <returns>.</returns>
public async Task<BlobDownloadResult> DownloadMediaInputAsset(string inputAssetName, string fileName)
{
IAzureMediaServicesClient client = await this.CreateMediaServicesClientAsync();
var client = this.GetMKIOServicesClientAsync();
var assets = client.Assets.Get(inputAssetName);

BlobServiceClient blobServiceClient = new BlobServiceClient(this.settings.MediaKindSettings.MediaKindStorageConnectionString);

AssetContainerSas assetContainerSas = await client.Assets.ListContainerSasAsync(
this.settings.AzureMediaResourceGroup,
this.settings.AzureMediaAccountName,
inputAssetName,
permissions: AssetContainerPermission.Read,
expiryTime: DateTime.UtcNow.AddHours(1).ToUniversalTime());
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(assets.Properties.Container);
if (!await containerClient.ExistsAsync().ConfigureAwait(false))
{
await containerClient.CreateIfNotExistsAsync().ConfigureAwait(false);
}

string sasUri = assetContainerSas.AssetContainerSasUrls.First();
var filename1 = Regex.Replace(fileName, "[^a-zA-Z0-9.]", string.Empty);
filename1 = string.IsNullOrEmpty(filename1) ? "file.txt" : filename1;

var blobServiceClient = new BlobContainerClient(new Uri(sasUri));
var blobClient = blobServiceClient.GetBlockBlobClient(fileName);
BlobClient blobClient = containerClient.GetBlobClient(filename1);
var fileContent = await blobClient.DownloadContentAsync();

return fileContent;
Expand Down
Loading