修改文件存储
This commit is contained in:
parent
ef9baadf92
commit
687160e0ae
@ -29,6 +29,12 @@ namespace Infrastructure.Enums
|
|||||||
/// 七牛
|
/// 七牛
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("七牛云")]
|
[Description("七牛云")]
|
||||||
QINIU = 4
|
QINIU = 4,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 远程
|
||||||
|
/// </summary>
|
||||||
|
[Description("远程")]
|
||||||
|
REMOTE = 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ namespace Infrastructure
|
|||||||
public class Upload
|
public class Upload
|
||||||
{
|
{
|
||||||
public string UploadUrl { get; set; }
|
public string UploadUrl { get; set; }
|
||||||
|
public string LocalSavePath { get; set; }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 阿里云存储
|
/// 阿里云存储
|
||||||
|
|||||||
@ -110,13 +110,15 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
switch (storeType)
|
switch (storeType)
|
||||||
{
|
{
|
||||||
case StoreType.LOCAL:
|
case StoreType.LOCAL:
|
||||||
string savePath = AppSettings.App(new string[] { "Upload", "localSavePath" });
|
string savePath = Path.Combine(WebHostEnvironment.WebRootPath);
|
||||||
if (savePath.IsEmpty())
|
if (fileDir.IsEmpty())
|
||||||
{
|
{
|
||||||
savePath = Path.Combine(WebHostEnvironment.WebRootPath, "uploads");
|
fileDir = AppSettings.App(new string[] { "Upload", "localSavePath" });
|
||||||
}
|
}
|
||||||
file = await SysFileService.SaveFileToLocal(savePath, fileName, fileDir, HttpContext.GetName(), formFile);
|
file = await SysFileService.SaveFileToLocal(savePath, fileName, fileDir, HttpContext.GetName(), formFile);
|
||||||
break;
|
break;
|
||||||
|
case StoreType.REMOTE:
|
||||||
|
break;
|
||||||
case StoreType.ALIYUN:
|
case StoreType.ALIYUN:
|
||||||
if ((fileSize / 1024) > MaxContentLength)
|
if ((fileSize / 1024) > MaxContentLength)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -20,8 +20,8 @@
|
|||||||
},
|
},
|
||||||
"DemoMode": false, //是否演示模式
|
"DemoMode": false, //是否演示模式
|
||||||
"Upload": {
|
"Upload": {
|
||||||
"UploadUrl": "http://localhost:8888",
|
"UploadUrl": "http://localhost:8888", //本地存储资源访问路径
|
||||||
"localSavePath": "" //本地上传文件存储目录/home/website/uploads
|
"localSavePath": "uploads" //本地上传默认文件存储目录 wwwroot/uploads
|
||||||
},
|
},
|
||||||
//阿里云存储配置
|
//阿里云存储配置
|
||||||
"ALIYUN_OSS": {
|
"ALIYUN_OSS": {
|
||||||
|
|||||||
@ -1,18 +1,17 @@
|
|||||||
using Infrastructure.Attribute;
|
using Infrastructure;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Infrastructure.Attribute;
|
||||||
using System.IO;
|
|
||||||
using ZR.Service.System.IService;
|
|
||||||
using ZR.Common;
|
|
||||||
using Infrastructure;
|
|
||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Net;
|
|
||||||
using ZR.Model.System;
|
|
||||||
using ZR.Repository.System;
|
|
||||||
using Infrastructure.Extensions;
|
using Infrastructure.Extensions;
|
||||||
using System.Threading.Tasks;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ZR.Common;
|
||||||
|
using ZR.Model.System;
|
||||||
|
using ZR.Service.System.IService;
|
||||||
|
|
||||||
namespace ZR.Service.System
|
namespace ZR.Service.System
|
||||||
{
|
{
|
||||||
@ -44,7 +43,7 @@ namespace ZR.Service.System
|
|||||||
{
|
{
|
||||||
string fileExt = Path.GetExtension(formFile.FileName);
|
string fileExt = Path.GetExtension(formFile.FileName);
|
||||||
fileName = (fileName.IsEmpty() ? HashFileName() : fileName) + fileExt;
|
fileName = (fileName.IsEmpty() ? HashFileName() : fileName) + fileExt;
|
||||||
|
|
||||||
string filePath = GetdirPath(fileDir);
|
string filePath = GetdirPath(fileDir);
|
||||||
string finalFilePath = Path.Combine(rootPath, filePath, fileName);
|
string finalFilePath = Path.Combine(rootPath, filePath, fileName);
|
||||||
double fileSize = Math.Round(formFile.Length / 1024.0, 2);
|
double fileSize = Math.Round(formFile.Length / 1024.0, 2);
|
||||||
@ -58,7 +57,7 @@ namespace ZR.Service.System
|
|||||||
{
|
{
|
||||||
await formFile.CopyToAsync(stream);
|
await formFile.CopyToAsync(stream);
|
||||||
}
|
}
|
||||||
string uploadUrl = SysConfigService.GetSysConfigByKey("sys.file.uploadUrl")?.ConfigValue ?? OptionsSetting.Upload.UploadUrl;
|
string uploadUrl = OptionsSetting.Upload.UploadUrl;
|
||||||
string accessPath = string.Concat(uploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName);
|
string accessPath = string.Concat(uploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName);
|
||||||
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName)
|
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user