diff --git a/LearningHub.Nhs.WebUI/Controllers/ResourceController.cs b/LearningHub.Nhs.WebUI/Controllers/ResourceController.cs index 3fe4b802d..206a16aac 100644 --- a/LearningHub.Nhs.WebUI/Controllers/ResourceController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/ResourceController.cs @@ -484,15 +484,24 @@ public async Task HtmlResourceContent(int resourceReferenceId, st contentType = "text/html"; } - var file = await this.fileService.DownloadFileAsync(contentFilePath, path); - if (file != null) + if (contentType.Contains("video") || contentType.Contains("audio")) { - return this.File(file.Content, contentType); + var stream = await this.fileService.StreamFileAsync(contentFilePath, path); + if (stream != null) + { + return this.File(stream, contentType, enableRangeProcessing: true); + } } else { - return this.Ok(this.Content("No file found")); + var file = await this.fileService.DownloadFileAsync(contentFilePath, path); + if (file != null) + { + return this.File(file.Content, contentType); + } } + + return this.Ok(this.Content("No file found")); } } } \ No newline at end of file diff --git a/LearningHub.Nhs.WebUI/Interfaces/IFileService.cs b/LearningHub.Nhs.WebUI/Interfaces/IFileService.cs index bed400074..e800efc41 100644 --- a/LearningHub.Nhs.WebUI/Interfaces/IFileService.cs +++ b/LearningHub.Nhs.WebUI/Interfaces/IFileService.cs @@ -27,6 +27,14 @@ public interface IFileService /// A representing the result of the asynchronous operation. Task DownloadFileAsync(string filePath, string fileName); + /// + /// The StreamFileAsync. + /// + /// The filePath. + /// The fileName. + /// The . + Task StreamFileAsync(string filePath, string fileName); + /// /// The ProcessFile. /// diff --git a/LearningHub.Nhs.WebUI/Services/FileService.cs b/LearningHub.Nhs.WebUI/Services/FileService.cs index 9c02d321e..4bfc997a5 100644 --- a/LearningHub.Nhs.WebUI/Services/FileService.cs +++ b/LearningHub.Nhs.WebUI/Services/FileService.cs @@ -143,6 +143,29 @@ public async Task DownloadFileAsync(string filePath, stri return null; } + /// + /// The StreamFileAsync. + /// + /// The filePath. + /// The fileName. + /// The . + public async Task StreamFileAsync(string filePath, string fileName) + { + var directory = this.ShareClient.GetDirectoryClient(filePath); + + if (await directory.ExistsAsync()) + { + var file = directory.GetFileClient(fileName); + + if (await file.ExistsAsync()) + { + return await file.OpenReadAsync(); + } + } + + return null; + } + /// /// The ProcessFile. ///