:sparkles:新增文件下载接口

This commit is contained in:
不做码农
2023-12-17 16:25:56 +08:00
parent 7c78ce8ed5
commit 0ee1ab8af5
4 changed files with 56 additions and 24 deletions
+6 -12
View File
@@ -55,13 +55,15 @@ namespace ZR.ServiceCore.Services
await formFile.CopyToAsync(stream);
}
string uploadUrl = OptionsSetting.Upload.UploadUrl;
string accessPath = string.Concat(uploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName);
string accessPath = string.Concat(filePath.Replace("\\", "/"), "/", fileName);
Uri baseUri = new(uploadUrl);
Uri fullUrl = new(baseUri, accessPath);
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName)
{
StoreType = (int)StoreType.LOCAL,
FileType = formFile.ContentType,
FileUrl = finalFilePath.Replace("\\", "/"),
AccessUrl = accessPath
AccessUrl = fullUrl.AbsoluteUri
};
file.Id = await InsertFile(file);
return file;
@@ -111,22 +113,14 @@ namespace ZR.ServiceCore.Services
{
if (string.IsNullOrEmpty(str))
{
str = Guid.NewGuid().ToString();
str = Guid.NewGuid().ToString().ToLower();
}
return BitConverter.ToString(MD5.HashData(Encoding.Default.GetBytes(str)), 4, 8).Replace("-", "");
}
public Task<long> InsertFile(SysFile file)
{
try
{
return Insertable(file).ExecuteReturnSnowflakeIdAsync();//单条插入返回雪花ID;
}
catch (Exception ex)
{
Console.WriteLine("存储图片失败" + ex.Message);
throw new Exception(ex.Message);
}
return Insertable(file).ExecuteReturnSnowflakeIdAsync();//单条插入返回雪花ID;
}
}
}