|
@@ -0,0 +1,61 @@
|
|
|
+using System.IO;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Aliyun.Acs.Core.Http;
|
|
|
+using Aliyun.Acs.Core.Utils;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.AspNetCore.StaticFiles;
|
|
|
+
|
|
|
+namespace GxPress.Api.AppControllers
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 访问
|
|
|
+ /// </summary>
|
|
|
+ [Route("/api/app/video")]
|
|
|
+ [ApiController]
|
|
|
+ [Authorize]
|
|
|
+ public class VideoController : ControllerBase
|
|
|
+ {
|
|
|
+ private readonly IWebHostEnvironment _environment;
|
|
|
+
|
|
|
+ public VideoController(IWebHostEnvironment environment)
|
|
|
+ {
|
|
|
+ _environment = environment;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet]
|
|
|
+ [AllowAnonymous]
|
|
|
+ public IActionResult GetVideo()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // HttpResponse response = new HttpResponse();
|
|
|
+ var dd = Common.Tools.StringUtils.GetWebRootPath(_environment.WebRootPath);
|
|
|
+ var fis = new FileStream(dd + "/cache/20200428/music.mp4", FileMode.Open);
|
|
|
+ var size = fis.Length; // 得到文件大小
|
|
|
+ var data = new byte[size];
|
|
|
+ fis.Write(data, 0, data.Length);
|
|
|
+ var filepath = dd + "/cache/20200428/music.mp4";
|
|
|
+ var provider = new FileExtensionContentTypeProvider();
|
|
|
+ FileInfo fileInfo = new FileInfo(filepath);
|
|
|
+ var ext = fileInfo.Extension;
|
|
|
+ new FileExtensionContentTypeProvider().Mappings.TryGetValue(ext, out var contenttype);
|
|
|
+ var result = File(data, contenttype ?? "application/octet-stream", fileInfo.Name);
|
|
|
+ fis.Close();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ catch (FileNotFoundException e)
|
|
|
+ {
|
|
|
+ throw new Common.Exceptions.BusinessException(e.Message);
|
|
|
+ }
|
|
|
+ catch (IOException e)
|
|
|
+ {
|
|
|
+ throw new Common.Exceptions.BusinessException(e.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|