Merge pull request 'BUG:文件上传' (#373) from koy07555/Admin.NET.Pro:BUG:文件上传BUG into v2

Reviewed-on: https://code.adminnet.top/Admin.NET/Admin.NET.Pro/pulls/373
This commit is contained in:
zuohuaijun 2025-07-16 10:20:30 +08:00
commit e075a58959

View File

@ -43,7 +43,7 @@ public class SysFileService : IDynamicApiController, ITransient
{
_customFileProvider = _namedServiceProvider.GetService<ITransient>(nameof(SSHFileProvider));
}
else if (App.Configuration["Upload:EnableSaveFileToDb"].ToBoolean())
else if (_uploadOptions.EnableSaveDb)
{
_customFileProvider = _namedServiceProvider.GetService<ITransient>(nameof(DbFileProvider));
}
@ -138,6 +138,7 @@ public class SysFileService : IDynamicApiController, ITransient
/// <returns></returns>
[HttpGet("/upload/downloadfile")]
[DisplayName("根据文件Id和MD5下载")]
[AllowAnonymous]
public async Task<IActionResult> DownloadFile2([FromQuery] long id, [FromQuery] string fileMd5)
{
var file = await GetFile(id);
@ -272,7 +273,10 @@ public class SysFileService : IDynamicApiController, ITransient
// 不管要不要验证md5也把Md6计算出来方便统计重复的文件。
await using (var fileStream = input.File.OpenReadStream())
{
fileMd5 = OssUtils.ComputeContentMd5(fileStream, fileStream.Length);
//fileMd5 = OssUtils.ComputeContentMd5(fileStream, fileStream.Length); // 这种返回的是base64字符串有"="这种特殊字符,格式不规范
byte[] bsFile = new byte[fileStream.Length];
_ = fileStream.Read(bsFile, 0, bsFile.Length);
fileMd5 = MD5Encryption.Encrypt(bsFile);// 使用这个返回长度为32的固定字符串
}
if (_uploadOptions.EnableMd5)
{