Skip to content

Commit 8f4dfa4

Browse files
OluwatobiAweAnjuJose011
authored andcommitted
Merge pull request #195 from TechnologyEnhancedLearning/Develop/Fixes/TD-3881
TD-3881 stream audio or video file content within html resource
1 parent 6ddefc0 commit 8f4dfa4

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

LearningHub.Nhs.WebUI/Controllers/ResourceController.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,24 @@ public async Task<IActionResult> HtmlResourceContent(int resourceReferenceId, st
486486
contentType = "text/html";
487487
}
488488

489-
var file = await this.fileService.DownloadFileAsync(contentFilePath, path);
490-
if (file != null)
489+
if (contentType.Contains("video") || contentType.Contains("audio"))
491490
{
492-
return this.File(file.Content, contentType);
491+
var stream = await this.fileService.StreamFileAsync(contentFilePath, path);
492+
if (stream != null)
493+
{
494+
return this.File(stream, contentType, enableRangeProcessing: true);
495+
}
493496
}
494497
else
495498
{
496-
return this.Ok(this.Content("No file found"));
499+
var file = await this.fileService.DownloadFileAsync(contentFilePath, path);
500+
if (file != null)
501+
{
502+
return this.File(file.Content, contentType);
503+
}
497504
}
505+
506+
return this.Ok(this.Content("No file found"));
498507
}
499508
}
500509
}

LearningHub.Nhs.WebUI/Interfaces/IFileService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public interface IFileService
2929
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
3030
Task<ShareFileDownloadInfo> DownloadFileAsync(string filePath, string fileName);
3131

32+
/// <summary>
33+
/// The StreamFileAsync.
34+
/// </summary>
35+
/// <param name="filePath">The filePath.</param>
36+
/// <param name="fileName">The fileName.</param>
37+
/// <returns>The <see cref="Task{Stream}"/>.</returns>
38+
Task<Stream> StreamFileAsync(string filePath, string fileName);
39+
3240
/// <summary>
3341
/// The ProcessFile.
3442
/// </summary>

LearningHub.Nhs.WebUI/Services/FileService.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ public async Task<ShareFileDownloadInfo> DownloadFileAsync(string filePath, stri
9898
return null;
9999
}
100100

101+
/// <summary>
102+
/// The StreamFileAsync.
103+
/// </summary>
104+
/// <param name="filePath">The filePath.</param>
105+
/// <param name="fileName">The fileName.</param>
106+
/// <returns>The <see cref="Task{Stream}"/>.</returns>
107+
public async Task<Stream> StreamFileAsync(string filePath, string fileName)
108+
{
109+
var directory = this.ShareClient.GetDirectoryClient(filePath);
110+
111+
if (await directory.ExistsAsync())
112+
{
113+
var file = directory.GetFileClient(fileName);
114+
115+
if (await file.ExistsAsync())
116+
{
117+
return await file.OpenReadAsync();
118+
}
119+
}
120+
121+
return null;
122+
}
123+
101124
/// <summary>
102125
/// The ProcessFile.
103126
/// </summary>

0 commit comments

Comments
 (0)