Browse Source

修改文件上传,统一后缀名为aks

develop-FileUpload-test
胡超1 2 years ago
parent
commit
1ad24b978a
  1. 69
      24Hour/Controllers/Common/CommonController.cs

69
24Hour/Controllers/Common/CommonController.cs

@ -8,7 +8,9 @@ using Elight.Utility;
using Elight.Utility.Code; using Elight.Utility.Code;
using Elight.Utility.Extensions; using Elight.Utility.Extensions;
using Elight.Utility.logs; using Elight.Utility.logs;
using java.io;
using java.util; using java.util;
using javax.smartcardio;
using javax.xml.crypto; using javax.xml.crypto;
using jdk.nashorn.@internal.ir; using jdk.nashorn.@internal.ir;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -1488,7 +1490,7 @@ namespace _24Hour.Controllers.Common
var Lawyerboldata = Lawyerbol.FirstOrDefault(); var Lawyerboldata = Lawyerbol.FirstOrDefault();
if (dto.Type == 1) if (dto.Type == 1)
{ {
if (Lawyerboldata.state ==4) if (Lawyerboldata.state == 4)
{ {
result.IsSucceed = false; result.IsSucceed = false;
result.result = "预约已被取消"; result.result = "预约已被取消";
@ -2747,7 +2749,7 @@ namespace _24Hour.Controllers.Common
public async Task<ActionResult> Upload_Files(IFormFile file) public async Task<ActionResult> Upload_Files(IFormFile file)
{ {
Result outParm = new Result(); Result outParm = new Result();
return await Task.Run(() => return await Task.Run(async () =>
{ {
if (file.Length <= 0) if (file.Length <= 0)
{ {
@ -2761,22 +2763,38 @@ namespace _24Hour.Controllers.Common
IFormFile file = Request.Form.Files.FirstOrDefault(); IFormFile file = Request.Form.Files.FirstOrDefault();
var fname = $@"{file.FileName}"; var fname = $@"{file.FileName}";
var hzname = $"{Path.GetExtension(fname)}"; var hzname = $"{Path.GetExtension(fname)}";
var _path = $"/CaseFile/video/{DateTime.Now.ToString("yyyy-MM-dd")}"; var _path = Path.Combine("CaseFile", "card", DateTime.Now.ToString("yyyy-MM-dd"));
var dic = Path.Combine(Environment.CurrentDirectory, "wwwroot"); var dic = Path.Combine(Environment.CurrentDirectory, "wwwroot", _path);
if (!string.IsNullOrEmpty(_path))
dic += _path;
if (!System.IO.Directory.Exists(dic)) if (!System.IO.Directory.Exists(dic))
Directory.CreateDirectory(dic); Directory.CreateDirectory(dic);
var filename = $"{DateTime.Now:yyyyMMddHHmmssfff}{Path.GetExtension(fname)}"; var filename = $"{DateTime.Now:yyyyMMddHHmmssfff}{Path.GetExtension(fname)}";
var filepath = Path.Combine(_path, $"{filename}"); var filepath = Path.Combine(_path, $"{filename}");
var path = Path.Combine(dic, $"{filename}"); var path = Path.Combine(dic, $"{filename}");
var __path = Path.Combine(_path, filename);
path = System.IO.Path.ChangeExtension(path, "aks");
using (var stream = new FileStream(path, FileMode.OpenOrCreate)) using (var stream = new FileStream(path, FileMode.OpenOrCreate))
{ {
file.CopyToAsync(stream).Wait(); await file.CopyToAsync(stream);
} }
var __path = $"{_path}/{filename}"; // var __path = $"{_path}/{filename}";
__path = System.IO.Path.ChangeExtension(__path, "aks");
var repath = "/" + __path.Replace(@"\", @"/");
outParm.IsSucceed = true; outParm.IsSucceed = true;
outParm.result = new { hzname = hzname, url = __path, tile = Path.GetFileNameWithoutExtension(file.FileName), size, DataPath = path, filePath = dic }; outParm.result = new
{
hzname = hzname,
url = repath,
tile = Path.GetFileNameWithoutExtension(file.FileName),
size,
DataPath = path,
filePath = dic
};
} }
catch (Exception e) catch (Exception e)
{ {
@ -2786,6 +2804,30 @@ namespace _24Hour.Controllers.Common
return Json(outParm); return Json(outParm);
}); });
} }
[HttpGet]
[Route("GetImageFile")]
public async Task<Result> GetImageFile(string file)
{
Result result = new Result();
var urlpath = file.Replace("/", @"\");
var path = Path.Combine(Environment.CurrentDirectory, "wwwroot"+urlpath);
if (System.IO.File.Exists(path))
{
var str = Convert.ToBase64String(System.IO.File.ReadAllBytes(path));
result.result = new
{
BaseStr = str
};
result.IsSucceed = true;
}
else
{
result.IsSucceed = false;
result.Message = "文件不存在";
}
return result;
}
/// <summary> /// <summary>
/// 文件上传--附件 /// 文件上传--附件
/// </summary> /// </summary>
@ -2794,6 +2836,7 @@ namespace _24Hour.Controllers.Common
[HttpPost] [HttpPost]
[Route("Upload_Files1")] [Route("Upload_Files1")]
[AllowAnonymous] [AllowAnonymous]
public async Task<ActionResult> Upload_Files1(IFormFile file) public async Task<ActionResult> Upload_Files1(IFormFile file)
{ {
Result outParm = new Result(); Result outParm = new Result();
@ -2819,12 +2862,18 @@ namespace _24Hour.Controllers.Common
var filename = $"{DateTime.Now:yyyyMMddHHmmssfff}{Path.GetExtension(fname)}"; var filename = $"{DateTime.Now:yyyyMMddHHmmssfff}{Path.GetExtension(fname)}";
var filepath = Path.Combine(_path, $"{filename}"); var filepath = Path.Combine(_path, $"{filename}");
var path = Path.Combine(dic, $"{filename}"); var path = Path.Combine(dic, $"{filename}");
var __path = Path.Combine(_path, filename);
path = System.IO.Path.ChangeExtension(path, "aks");
using (var stream = new FileStream(path, FileMode.OpenOrCreate)) using (var stream = new FileStream(path, FileMode.OpenOrCreate))
{ {
await file.CopyToAsync(stream); await file.CopyToAsync(stream);
} }
// var __path = $"{_path}/{filename}"; // var __path = $"{_path}/{filename}";
var __path = Path.Combine(_path, filename);
__path = System.IO.Path.ChangeExtension(__path, "aks");
var repath = "/" + __path.Replace(@"\", @"/"); var repath = "/" + __path.Replace(@"\", @"/");

Loading…
Cancel
Save