Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 13 additions & 4 deletions LearningHub.Nhs.WebUI/Controllers/ResourceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,24 @@ public async Task<IActionResult> 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"));
}
}
}
8 changes: 8 additions & 0 deletions LearningHub.Nhs.WebUI/Interfaces/IFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public interface IFileService
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
Task<ShareFileDownloadInfo> DownloadFileAsync(string filePath, string fileName);

/// <summary>
/// The StreamFileAsync.
/// </summary>
/// <param name="filePath">The filePath.</param>
/// <param name="fileName">The fileName.</param>
/// <returns>The <see cref="Task{Stream}"/>.</returns>
Task<Stream> StreamFileAsync(string filePath, string fileName);

/// <summary>
/// The ProcessFile.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions LearningHub.Nhs.WebUI/Services/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,29 @@ public async Task<ShareFileDownloadInfo> DownloadFileAsync(string filePath, stri
return null;
}

/// <summary>
/// The StreamFileAsync.
/// </summary>
/// <param name="filePath">The filePath.</param>
/// <param name="fileName">The fileName.</param>
/// <returns>The <see cref="Task{Stream}"/>.</returns>
public async Task<Stream> 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;
}

/// <summary>
/// The ProcessFile.
/// </summary>
Expand Down