添加报工人
This commit is contained in:
@@ -69,6 +69,50 @@ namespace DOAN.ServiceCore.Services
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 存储本地
|
||||
/// </summary>
|
||||
/// <param name="fileDir">存储文件夹</param>
|
||||
/// <param name="rootPath">存储根目录</param>
|
||||
/// <param name="fileName">自定文件名</param>
|
||||
/// <param name="formFile">上传的文件流</param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="filePath">文件路径</param>
|
||||
/// <returns></returns>
|
||||
public async Task<SysFile> SaveFileToLocal(string rootPath, string fileName, string fileDir, string userName, IFormFile formFile, string filePath)
|
||||
{
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
fileName = (fileName.IsEmpty() ? HashFileName() : fileName) + fileExt;
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
filePath = GetdirPath(fileDir);
|
||||
}
|
||||
|
||||
string finalFilePath = Path.Combine(rootPath, filePath, fileName);
|
||||
double fileSize = Math.Round(formFile.Length / 1024.0, 2);
|
||||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(finalFilePath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(finalFilePath));
|
||||
}
|
||||
|
||||
using (var stream = new FileStream(finalFilePath, FileMode.Create))
|
||||
{
|
||||
await formFile.CopyToAsync(stream);
|
||||
}
|
||||
string uploadUrl = OptionsSetting.Upload.UploadUrl;
|
||||
string accessPath = string.Concat(uploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName);
|
||||
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName)
|
||||
{
|
||||
StoreType = (int)StoreType.LOCAL,
|
||||
FileType = formFile.ContentType,
|
||||
FileUrl = finalFilePath.Replace("\\", "/"),
|
||||
AccessUrl = accessPath
|
||||
};
|
||||
file.Id = await InsertFile(file);
|
||||
return file;
|
||||
}
|
||||
/// <summary>
|
||||
/// 上传文件到阿里云
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user