服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-06-21 6922ceb192bfcb15f840409bb5f0707d3ee448e9
Tiger.Api/Controllers/Base/BaseController.cs
@@ -10,6 +10,7 @@
using Newtonsoft.Json;
using Tiger.IBusiness;
using Tiger.Api.iBiz;
using System.IO;
namespace Tiger.Api.Controllers.Base
{
@@ -530,5 +531,29 @@
            return Ok(response);
        }
        #endregion
        #region 文件上传
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Upload(IFormFile file)
        {
            if (file == null || file.Length == 0)
                return BadRequest("No file uploaded.");
            var path = Path.Combine($@"{BizConfig.Configuration["UploadAddress"]}", "upload", file.FileName);
            using (var stream = new FileStream(path, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }
            return Ok(new { file.FileName, file.ContentType, file.Length, url= $@"{BizConfig.Configuration["DownloadAddress"]}/"+ file.FileName });
        }
        #endregion
    }
}