Skip to content

Commit 61464c8

Browse files
Merge pull request #999 from TechnologyEnhancedLearning/Develop/Fixes/TD-5012-Issue-couldn't-able-to-download-File-Audio/Video-resources-from-Resources-section-on-Admin-UI
TD-5012: Issue couldn't able to download File Audio/Video resources f…
2 parents 687c8d8 + 6b01042 commit 61464c8

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

AdminUI/LearningHub.Nhs.AdminUI/Services/MKIOMediaService.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,21 @@ public async Task<string> CreateMediaInputAsset(IFormFile file)
9191
/// <returns>.</returns>
9292
public async Task<BlobDownloadResult> DownloadMediaInputAsset(string inputAssetName, string fileName)
9393
{
94-
IAzureMediaServicesClient client = await this.CreateMediaServicesClientAsync();
94+
var client = this.GetMKIOServicesClientAsync();
95+
var assets = client.Assets.Get(inputAssetName);
96+
97+
BlobServiceClient blobServiceClient = new BlobServiceClient(this.settings.MediaKindSettings.MediaKindStorageConnectionString);
9598

96-
AssetContainerSas assetContainerSas = await client.Assets.ListContainerSasAsync(
97-
this.settings.AzureMediaResourceGroup,
98-
this.settings.AzureMediaAccountName,
99-
inputAssetName,
100-
permissions: AssetContainerPermission.Read,
101-
expiryTime: DateTime.UtcNow.AddHours(1).ToUniversalTime());
99+
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(assets.Properties.Container);
100+
if (!await containerClient.ExistsAsync().ConfigureAwait(false))
101+
{
102+
await containerClient.CreateIfNotExistsAsync().ConfigureAwait(false);
103+
}
102104

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

105-
var blobServiceClient = new BlobContainerClient(new Uri(sasUri));
106-
var blobClient = blobServiceClient.GetBlockBlobClient(fileName);
108+
BlobClient blobClient = containerClient.GetBlobClient(filename1);
107109
var fileContent = await blobClient.DownloadContentAsync();
108110

109111
return fileContent;

0 commit comments

Comments
 (0)