2023-08-04

This commit is contained in:
2023-08-04 17:06:50 +08:00
parent 70a51ab125
commit 78e8037f08
81 changed files with 8897 additions and 2763 deletions
+45 -31
View File
@@ -1,5 +1,6 @@
using BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.IO;
@@ -30,6 +31,9 @@ namespace WebAPI.Controllers
{
typeName = "WebApi";
}
// 定义允许上传的文件类型列表
List<string> allowExtensions = BLL.DropListService.allowExtensions;
string reUrl = string.Empty;
if (files != null && files.Count > 0)
{
@@ -45,6 +49,10 @@ namespace WebAPI.Controllers
string fileName = string.Empty;
string extensionstr = string.Empty;
HttpPostedFile file = files[key];//file.ContentLength文件长度
if (!allowExtensions.Contains(Path.GetExtension(file.FileName)))
{
return BadRequest($"Invalid file extension: {file.FileName}");
}
if (!string.IsNullOrEmpty(file.FileName))
{
extensionstr = Path.GetExtension(file.FileName).ToLower();
@@ -139,6 +147,42 @@ namespace WebAPI.Controllers
return responeData;
}
#endregion
#region
/// <summary>
/// 附件上传
/// </summary>
/// <returns></returns>
public IHttpActionResult PostSmall()
{
HttpFileCollection files = HttpContext.Current.Request.Files;
string typeName = HttpContext.Current.Request["typeName"];
if (string.IsNullOrEmpty(typeName))
{
typeName = "WebApi";
}
string reUrl = string.Empty;
if (files != null && files.Count > 0)
{
string folderUrl = "FileUpLoad/" + typeName + "/" + DateTime.Now.ToString("yyyy-MM") + "/";
string localRoot = ConfigurationManager.AppSettings["localRoot"] + folderUrl; //物理路径
if (!Directory.Exists(localRoot))
{
Directory.CreateDirectory(localRoot);
}
foreach (string key in files.AllKeys)
{
HttpPostedFile file = files[key];//file.ContentLength文件长度
reUrl = UpLoadImageService.UpLoadImage(file, folderUrl, folderUrl + "Small/", 80, 30);
}
}
return Ok(reUrl);
}
#endregion
#region 线
/// <summary>
/// 在线编辑回调保存文件
/// </summary>
@@ -190,37 +234,7 @@ namespace WebAPI.Controllers
return responeData;
}
#region
/// <summary>
/// 附件上传
/// </summary>
/// <returns></returns>
public IHttpActionResult PostSmall()
{
HttpFileCollection files = HttpContext.Current.Request.Files;
string typeName = HttpContext.Current.Request["typeName"];
if (string.IsNullOrEmpty(typeName))
{
typeName = "WebApi";
}
string reUrl = string.Empty;
if (files != null && files.Count > 0)
{
string folderUrl = "FileUpLoad/" + typeName + "/" + DateTime.Now.ToString("yyyy-MM") + "/";
string localRoot = ConfigurationManager.AppSettings["localRoot"] + folderUrl; //物理路径
if (!Directory.Exists(localRoot))
{
Directory.CreateDirectory(localRoot);
}
foreach (string key in files.AllKeys)
{
HttpPostedFile file = files[key];//file.ContentLength文件长度
reUrl = UpLoadImageService.UpLoadImage(file, folderUrl, folderUrl + "Small/", 80, 30);
}
}
return Ok(reUrl);
}
#endregion
}
}