|
|
|
@ -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 |
|
|
|
|
|
|
|
|
|