附件上传
This commit is contained in:
parent
60a4bc3644
commit
582db250d5
@ -133,15 +133,16 @@ namespace MineTec.ProManager.GalleryFiles
|
||||
}
|
||||
|
||||
//单个文件上传
|
||||
public async Task<string> UploadFilessss(IFormFile file)
|
||||
public async Task<string> UploadFile(IFormFile file)
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
return "请先选择文件";
|
||||
}
|
||||
string webRootPath = @"D:\UploadingFiles\"; // wwwroot 文件夹
|
||||
string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd"));
|
||||
string webRootPath = @"D:\UploadingFiles\"; //保存文件路径
|
||||
string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd"));//增加日期文件夹
|
||||
string dirPath = Path.Combine(webRootPath, uploadPath);
|
||||
//创建路径
|
||||
if (!Directory.Exists(dirPath))
|
||||
{
|
||||
Directory.CreateDirectory(dirPath);
|
||||
@ -159,33 +160,34 @@ namespace MineTec.ProManager.GalleryFiles
|
||||
}
|
||||
|
||||
//多个文件上传
|
||||
public async Task<string> UploadPhotoszzzzz(IFormFileCollection files)
|
||||
public async Task<string> UploadFiles(IFormFileCollection files)
|
||||
{
|
||||
long size = files.Sum(f => f.Length);
|
||||
|
||||
string webRootPath = @"D:\UploadingFiles\"; // wwwroot 文件夹
|
||||
string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd"));
|
||||
string fileFolder = Path.Combine(webRootPath, uploadPath);
|
||||
|
||||
if (!Directory.Exists(fileFolder))
|
||||
Directory.CreateDirectory(fileFolder);
|
||||
|
||||
if (files.Count() == 0)
|
||||
{
|
||||
return "请先选择文件";
|
||||
}
|
||||
string webRootPath = @"D:\UploadingFiles\"; //保存文件路径
|
||||
string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd"));//增加日期文件夹
|
||||
string dirPath = Path.Combine(webRootPath, uploadPath);
|
||||
//创建路径
|
||||
if (!Directory.Exists(dirPath))
|
||||
{
|
||||
Directory.CreateDirectory(dirPath);
|
||||
}
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (file.Length > 0)
|
||||
{
|
||||
var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") +
|
||||
Path.GetExtension(file.FileName);
|
||||
var filePath = Path.Combine(fileFolder, fileName);
|
||||
|
||||
using (var stream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
await file.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
string fileExt = Path.GetExtension(file.FileName).Trim('.'); //文件扩展名,不含“.”
|
||||
string newFileName = Guid.NewGuid().ToString().Replace("-", "") + "." + fileExt; //随机生成新的文件名
|
||||
var filePath = Path.Combine(dirPath, newFileName);
|
||||
|
||||
using (var stream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
await file.CopyToAsync(stream);
|
||||
}
|
||||
}
|
||||
|
||||
var url = $@"\{uploadPath}\11";
|
||||
var url = $@"\{uploadPath}\{dirPath}";
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user