From 345bbfe1bf354289dfc8f699d5eb2c18e5cf83a6 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Wed, 27 Oct 2021 09:10:13 +0800 Subject: [PATCH] fix(oss): when oss is created, the directory is created if the data is empty --- .../Abp/OssManagement/FileAppServiceBase.cs | 1 + .../Abp/OssManagement/OssObjectAppService.cs | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/FileAppServiceBase.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/FileAppServiceBase.cs index d8d2cce2b..4c143df8f 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/FileAppServiceBase.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/FileAppServiceBase.cs @@ -24,6 +24,7 @@ namespace LINGYUN.Abp.OssManagement _ossContainerFactory = ossContainerFactory; } + [RequiresFeature(AbpOssManagementFeatureNames.OssObject.UploadFile)] public virtual async Task UploadAsync(UploadFileChunkInput input) { await _fileUploader.UploadAsync( diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/OssObjectAppService.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/OssObjectAppService.cs index 81b84681e..024bd5a3c 100644 --- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/OssObjectAppService.cs +++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.Application/LINGYUN/Abp/OssManagement/OssObjectAppService.cs @@ -1,6 +1,8 @@ using LINGYUN.Abp.OssManagement.Permissions; using Microsoft.AspNetCore.Authorization; +using System.IO; using System.Threading.Tasks; +using System.Web; namespace LINGYUN.Abp.OssManagement { @@ -21,9 +23,25 @@ namespace LINGYUN.Abp.OssManagement [Authorize(AbpOssManagementPermissions.OssObject.Create)] public virtual async Task CreateAsync(CreateOssObjectInput input) { - var ossObject = await Merger.MergeAsync(input); + // 内容为空时建立目录 + if (input.Content.IsNullOrEmpty()) + { + var oss = CreateOssContainer(); + var request = new CreateOssObjectRequest( + HttpUtility.UrlDecode(input.Bucket), + HttpUtility.UrlDecode(input.Object), + input.Content, + HttpUtility.UrlDecode(input.Path)); + var ossObject = await oss.CreateObjectAsync(request); - return ObjectMapper.Map(ossObject); + return ObjectMapper.Map(ossObject); + } + else + { + var ossObject = await Merger.MergeAsync(input); + + return ObjectMapper.Map(ossObject); + } } [Authorize(AbpOssManagementPermissions.OssObject.Delete)]