diff --git a/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/DownloadFileObjectInput.cs b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/DownloadFileObjectInput.cs new file mode 100644 index 00000000..47cc31f0 --- /dev/null +++ b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/DownloadFileObjectInput.cs @@ -0,0 +1,9 @@ +namespace Lion.AbpPro.FileManagement.Files; + +public class DownloadFileObjectInput +{ + /// + /// 文件Id + /// + public Guid Id { get; set; } +} \ No newline at end of file diff --git a/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/IFileAppService.cs b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/IFileAppService.cs index f43c32c3..8ebfe68c 100644 --- a/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/IFileAppService.cs +++ b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/IFileAppService.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; @@ -25,4 +26,9 @@ public interface IFileAppService : IApplicationService Task DeleteAsync(DeleteFileObjectInput input); Task GetAsync(GetFileObjectInput input); + + /// + /// 下载文件 + /// + Task DownloadAsync(DownloadFileObjectInput input); } \ No newline at end of file diff --git a/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Lion.AbpPro.FileManagement.Application.Contracts.csproj b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Lion.AbpPro.FileManagement.Application.Contracts.csproj index 9dc1d21f..766bc2ac 100644 --- a/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Lion.AbpPro.FileManagement.Application.Contracts.csproj +++ b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Lion.AbpPro.FileManagement.Application.Contracts.csproj @@ -7,6 +7,7 @@ + diff --git a/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application/Files/FileAppService.cs b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application/Files/FileAppService.cs index 71f9f7e3..14b2da5b 100644 --- a/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application/Files/FileAppService.cs +++ b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application/Files/FileAppService.cs @@ -1,5 +1,6 @@ using Lion.AbpPro.FileManagement.Provider; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace Lion.AbpPro.FileManagement.Files; @@ -94,4 +95,10 @@ public class FileAppService : ApplicationService, IFileAppService var file = await _fileObjectManager.GetAsync(input.Id); return ObjectMapper.Map(file); } + + public async Task DownloadAsync(DownloadFileObjectInput input) + { + var file = await _fileObjectManager.GetAsync(input.Id); + return new Microsoft.AspNetCore.Mvc.FileContentResult(file.Bytes, file.ContentType); + } } \ No newline at end of file diff --git a/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.HttpApi/Files/FileController.cs b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.HttpApi/Files/FileController.cs index 0473a610..b310fb34 100644 --- a/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.HttpApi/Files/FileController.cs +++ b/aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.HttpApi/Files/FileController.cs @@ -40,4 +40,11 @@ public class FileController : AbpController, IFileAppService { return _fileAppService.GetAsync(input); } + + [HttpPost("Download")] + [SwaggerOperation(summary: "下载文件", Tags = new[] { "Files" })] + public Task DownloadAsync(DownloadFileObjectInput input) + { + return _fileAppService.DownloadAsync(input); + } } \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs index f7d91c61..490e955f 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs @@ -88,7 +88,6 @@ namespace Lion.AbpPro // }); }); - app.UseConfiguredEndpoints(endpoints => { endpoints.MapHealthChecks("/health"); }); if (configuration.GetValue("Consul:Enabled", false)) {