diff --git a/Tiobon.Core.Api/Controllers/FileController.cs b/Tiobon.Core.Api/Controllers/FileController.cs
index caee4845..5d19941f 100644
--- a/Tiobon.Core.Api/Controllers/FileController.cs
+++ b/Tiobon.Core.Api/Controllers/FileController.cs
@@ -145,4 +145,22 @@ public class FileController : BaseApiController
}
#endregion
+ #region 分片上传
+ ///
+ /// 分片上传
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpPost("UploadLarge")]
+ public async Task UploadLargeAsync(IFormFile file, string videoName, int chunkIndex, int totalChunks, string id)
+ {
+ dynamic obj = await _ghre_AttachmentServices.UploadVideoAsync(file, videoName, chunkIndex, totalChunks, id);
+ return Ok(obj);
+ }
+ #endregion
+
}
\ No newline at end of file
diff --git a/Tiobon.Core.IServices/Ghre/IGhre_AttachmentServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_AttachmentServices.cs
index 14684e30..79c08d74 100644
--- a/Tiobon.Core.IServices/Ghre/IGhre_AttachmentServices.cs
+++ b/Tiobon.Core.IServices/Ghre/IGhre_AttachmentServices.cs
@@ -1,4 +1,5 @@
-using Tiobon.Core.IServices.BASE;
+using Microsoft.AspNetCore.Http;
+using Tiobon.Core.IServices.BASE;
using Tiobon.Core.Model.Models;
namespace Tiobon.Core.IServices
@@ -8,5 +9,7 @@ namespace Tiobon.Core.IServices
///
public interface IGhre_AttachmentServices :IBaseServices
{
+ Task UploadVideoAsync(IFormFile file, string videoName, int chunkIndex, int totalChunks, string id);
+
}
}
\ No newline at end of file
diff --git a/Tiobon.Core.Services/Ghre/Ghre_AttachmentServices.cs b/Tiobon.Core.Services/Ghre/Ghre_AttachmentServices.cs
index dcbc32ee..f803902a 100644
--- a/Tiobon.Core.Services/Ghre/Ghre_AttachmentServices.cs
+++ b/Tiobon.Core.Services/Ghre/Ghre_AttachmentServices.cs
@@ -3,12 +3,15 @@ using Tiobon.Core.IServices;
using Tiobon.Core.Model.Models;
using Tiobon.Core.Services.BASE;
using Tiobon.Core.IRepository.Base;
+using Microsoft.AspNetCore.Http;
+using System.Dynamic;
+using SqlSugar;
namespace Tiobon.Core.Services
{
- ///
- /// 附件 (服务)
- ///
+ ///
+ /// 附件 (服务)
+ ///
public class Ghre_AttachmentServices : BaseServices, IGhre_AttachmentServices
{
private readonly IBaseRepository _dal;
@@ -17,5 +20,74 @@ namespace Tiobon.Core.Services
this._dal = dal;
base.BaseDal = dal;
}
+
+ public async Task UploadVideoAsync(IFormFile file, string videoName, int chunkIndex, int totalChunks, string id)
+ {
+ dynamic obj = new ExpandoObject();
+ string status = "error";
+ string message = string.Empty;
+ string pathHeader = string.Empty;
+ string url = string.Empty;
+
+ try
+ {
+ var path = $"{$"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}upload{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}";
+ if (!Directory.Exists(path))
+ Directory.CreateDirectory(path);
+ using (var stream = File.Create(path + $"{chunkIndex}"))
+ {
+ await file.CopyToAsync(stream);
+ }
+
+ if (chunkIndex == totalChunks - 1)
+ await FileMerge(id, ".mp4", SnowFlakeSingle.Instance.NextId());
+
+ status = "ok";
+ }
+ catch (Exception E)
+ {
+ message = E.Message;
+ }
+ obj.url = url;
+ obj.status = status;
+ obj.message = message;
+ return obj;
+ }
+
+ public static async Task