/// <summary>
/// 编辑器上传接口
/// </summary>
/// <returns></returns>
[HttpPost("CKEFileUpload")]
[AbpAllowAnonymous]
[DisableAuditing]
[IgnoreAntiforgeryToken]
[WrapResult(false)]
public JsonResult CKEFileUpload([FromForm] object upload)
{
var file = Request.Form.Files.FirstOrDefault();
string saveRoute = "UploadImage";
var MaxFile = 1;
if ((MaxFile * (1024 * 1024)) < file.Length)
{
return Json(new { uploaded = 0, success = false, error = new { message = $"上传的文件过大,最大仅支持[{MaxFile}MB]" } });
}
if (file != null)
{
string rootPath = Path.Combine(_hostingEnvironment.WebRootPath, saveRoute);
if (!Directory.Exists(rootPath))//不存在就创建目录
{
Directory.CreateDirectory(rootPath);
}
string FileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
var filePath = Path.Combine(rootPath, FileName);
if (System.IO.File.Exists(filePath))//如果有同名文件,则进行重命名
{
FileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
filePath = Path.Combine(rootPath, FileName);
}
using (var stream = System.IO.File.Create(filePath))//文件保存
{
file.CopyTo(stream);
}
return Json(new { uploaded = 1, url = Path.Combine("/" + saveRoute, FileName) });
}
return Json(new { uploaded = 0 });
}
C# APB 框架富文本上传图片接口
于 2023-05-01 23:28:59 首次发布