服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-05-29 9bf08164f52132c5beb53521b44a87547b97630e
文件上传功能及配置
已修改2个文件
28 ■■■■■ 文件已修改
Tiger.Api/Controllers/Base/BaseController.cs 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business/BizSettings.json 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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(@"D:\nginx-1.26.0\html", "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
    }
}
Tiger.Business/BizSettings.json
@@ -84,5 +84,6 @@
  "CurrentProject": "MqBarcode",
  "JuDian": "XCSJ",
  "IsTestServer": false,
  "IsUseDbCache": false
  "IsUseDbCache": false,
  "DownloadAddress": "http://47.115.28.255:8800/files"
}