Study 上传 迁移
This commit is contained in:
@@ -24,6 +24,13 @@ using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Aliyun.Acs.Core.Profile;
|
||||
using Aliyun.Acs.Core.Auth.Sts;
|
||||
using Aliyun.Acs.Core;
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace IRaCIS.Api.Controllers
|
||||
{
|
||||
@@ -203,6 +210,44 @@ namespace IRaCIS.Api.Controllers
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("user/GenerateSTS")]
|
||||
public IResponseOutput GenerateSTS(IOptionsMonitor<AliyunOssOptions> options )
|
||||
{
|
||||
var ossOptions = options.CurrentValue;
|
||||
|
||||
|
||||
IClientProfile profile = DefaultProfile.GetProfile(ossOptions.RegionId, ossOptions.AccessKeyId, ossOptions.AccessKeySecret);
|
||||
DefaultAcsClient client = new DefaultAcsClient(profile);
|
||||
|
||||
|
||||
// 创建一个STS请求
|
||||
AssumeRoleRequest request = new AssumeRoleRequest
|
||||
{
|
||||
RoleArn = ossOptions.RoleArn, // 角色ARN,需要替换为你的角色ARN
|
||||
RoleSessionName = $"session-name-{NewId.NextGuid()}", // 角色会话名称,可自定义
|
||||
DurationSeconds = 900, // 令牌有效期(单位:秒),这里设置为1小时
|
||||
};
|
||||
|
||||
|
||||
AssumeRoleResponse response = client.GetAcsResponse(request);
|
||||
|
||||
// 返回STS令牌信息给前端
|
||||
var stsToken = new
|
||||
{
|
||||
AccessKeyId = response.Credentials.AccessKeyId,
|
||||
AccessKeySecret = response.Credentials.AccessKeySecret,
|
||||
SecurityToken = response.Credentials.SecurityToken,
|
||||
Expiration = response.Credentials.Expiration,
|
||||
|
||||
Region = ossOptions.Region ,
|
||||
BucketName = ossOptions.BucketName ,
|
||||
ViewEndpoint = ossOptions.ViewEndpoint ,
|
||||
|
||||
};
|
||||
|
||||
return ResponseOutput.Ok(stsToken);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1222,6 +1222,59 @@ namespace IRaCIS.Core.API.Controllers
|
||||
|
||||
}
|
||||
|
||||
public enum UploadFileType
|
||||
{
|
||||
DataUpload = 1,
|
||||
|
||||
DataDownload = 2,
|
||||
|
||||
EmailAttachment = 3,
|
||||
|
||||
EmailBodyHtml = 4,
|
||||
|
||||
Other = 5
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 1:数据上传 2:导出、 3:邮件附件 4:邮件Html 通过 ----new
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("SystemFile/Upload")]
|
||||
[DisableRequestSizeLimit]
|
||||
[DisableFormValueModelBinding]
|
||||
public async Task<IResponseOutput> Upload(UploadFileType fileType)
|
||||
{
|
||||
IResponseOutput result = null;
|
||||
|
||||
switch (fileType)
|
||||
{
|
||||
case UploadFileType.DataUpload:
|
||||
result = await SingleFileUploadAsync((fileName) => FileStoreHelper.GetSystemFileUploadPath(_hostEnvironment, StaticData.Folder.DataTemplate, fileName));
|
||||
|
||||
break;
|
||||
case UploadFileType.DataDownload:
|
||||
result = await SingleFileUploadAsync((fileName) => FileStoreHelper.GetSystemFileUploadPath(_hostEnvironment, StaticData.Folder.DataTemplate, fileName));
|
||||
|
||||
break;
|
||||
case UploadFileType.EmailAttachment:
|
||||
result = await SingleFileUploadAsync((fileName) => FileStoreHelper.GetSystemFileUploadPath(_hostEnvironment, StaticData.Folder.EmailTemplate, fileName));
|
||||
|
||||
break;
|
||||
|
||||
case UploadFileType.EmailBodyHtml:
|
||||
result = await SingleFileUploadAsync((fileName) => FileStoreHelper.GetSystemFileUploadPath(_hostEnvironment, StaticData.Folder.EmailTemplate, fileName));
|
||||
break;
|
||||
|
||||
default:
|
||||
result = await SingleFileUploadAsync((fileName) => FileStoreHelper.GetOtherFileUploadPath(_hostEnvironment, StaticData.Folder.TempFile, fileName));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user