API endpoint which streams a media file by supplying the media id

This commit is contained in:
2020-06-02 14:12:56 +02:00
parent 5876e259b2
commit cf7927f4ff
5 changed files with 65 additions and 6 deletions
+26
View File
@@ -1,7 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using zero.Core.Api;
@@ -100,5 +102,29 @@ namespace zero.Web.Controllers
{
return await As<Media, MediaEditModel>(await Api.Delete(id));
}
/// <summary>
/// Streams a media thumbnail by id
/// </summary>
[HttpGet]
public async Task<IActionResult> StreamThumbnail(string id)
{
string path = await Api.GetSourceById(id, true);
if (path == null)
{
return NotFound();
}
var provider = new FileExtensionContentTypeProvider();
string contentType;
if (!provider.TryGetContentType(Path.GetFileName(path), out contentType))
{
contentType = "application/octet-stream";
}
return File(path, contentType);
}
}
}