文件上传修改

master
xiaochanghai 12 months ago
parent 1f8a3d3d37
commit fcd6383fae
  1. 1350
      Model/Tiobon.Web.pdm
  2. 60
      Tiobon.Core.Api/Controllers/FileController.cs
  3. 30
      Tiobon.Core.Model/ViewModels/FileUpload.cs
  4. 22
      Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs

File diff suppressed because it is too large Load Diff

@ -88,6 +88,66 @@ public class FileController : BaseApiController
}
return Success<string>(filePath);
}
[HttpPost, Route("Upload")]
public async Task<ServiceResult<FileUploadResult>> UploadAsync(FileUpload upload)
{
string filePath = null;
using var _context = ContextFactory.CreateContext();
filePath = !string.IsNullOrEmpty(filePath) ? filePath : "upload";
var ext = string.Empty;
if (string.IsNullOrEmpty(upload.file.FileName) == false)
{
var dotPos = upload.file.FileName.LastIndexOf('.');
ext = upload.file.FileName.Substring(dotPos + 1);
}
upload.fileName = upload.fileName ?? upload.file.FileName;
string pathHeader = "wwwroot/files/" + filePath;
if (!Directory.Exists(pathHeader))
Directory.CreateDirectory(pathHeader);
long fileName = SnowFlakeSingle.instance.getID();
filePath = "/files/" + filePath + "/" + $"{upload.fileName}_{fileName}.{ext}";
//var filepath = Path.Combine(pathHeader, file.FileName);
using (var stream = global::System.IO.File.Create("wwwroot/" + filePath))
{
await upload.file.CopyToAsync(stream);
}
var fileAttachment = new Ghre_Attachment();
fileAttachment.Id = SnowFlakeSingle.Instance.NextId();
fileAttachment.AttachmentNo = upload.file.FileName;
fileAttachment.AttachFileName = upload.file.FileName;
fileAttachment.CreateBy = App.User.ID;
fileAttachment.CreateTime = DateTime.Now;
fileAttachment.AttachmentName = fileName.ToString();
fileAttachment.AttachFileExtension = ext;
fileAttachment.AttachFileSize = upload.file.Length;
fileAttachment.PhysicsPath = filePath;
fileAttachment.RelativePath = filePath;
fileAttachment.FileURL = filePath;
fileAttachment.ThumbnailPath = filePath;
fileAttachment.AttachmentType = upload.file.ContentType;
//url = fileName + "." + ext;
_context.Add(fileAttachment);
_context.SaveChanges();
return Success(new FileUploadResult()
{
Id = fileAttachment.Id,
AttachFileExtension = fileAttachment.AttachFileExtension,
AttachFileName = fileAttachment.AttachFileName,
AttachmentName = fileAttachment.AttachmentName,
AttachmentNo = fileAttachment.AttachmentNo,
FileURL = fileAttachment.FileURL,
PhysicsPath = fileAttachment.PhysicsPath,
RelativePath = fileAttachment.RelativePath,
ThumbnailPath = fileAttachment.ThumbnailPath,
AttachFileSize = fileAttachment.AttachFileSize,
});
}
#endregion

@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Http;
namespace Tiobon.Core.Model.ViewModels;
public class FileUpload
{
public IFormFile file { get; set; }
public string fileName { get; set; }
public string userId { get; set; }
public string langId { get; set; }
}
public class FileUploadResult
{
public long Id { get; set; }
public string AttachFileExtension { get; set; }
public string AttachFileName { get; set; }
public string AttachmentName { get; set; }
public string AttachmentNo { get; set; }
public string FileURL { get; set; }
public string PhysicsPath { get; set; }
public string RelativePath { get; set; }
public string ThumbnailPath { get; set; }
public long? AttachFileSize { get; set; }
}

@ -236,17 +236,17 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
AND B.RoleNo LIKE 'TrainingExam%'";
var toolbarRoles = DbAccess.QueryList<ToolbarRole>(sql);
//if (toolbars.Any(x => x.fnKey == "NewYN"))
// Toolbar.Add(new Toolbar()
// {
// fnKey = "NewYN",
// fnKeyValue = null,
// fnTitle = "新增",
// fnType = "table",
// position = "left",
// icon = "ghr-icon-add",
// display = true
// });
if (toolbars.Any(x => x.fnKey == "NewYN"))
Toolbar.Add(new Toolbar()
{
fnKey = "NewYN",
fnKeyValue = null,
fnTitle = "新增",
fnType = "table",
position = "left",
icon = "ghr-icon-add",
display = true
});
if (param.menuName == "F_ExamManageDraft")
Toolbar.Add(new Toolbar()
{

Loading…
Cancel
Save