From 3c538400caa5ff783a263ca3eb64132385ded472 Mon Sep 17 00:00:00 2001 From: Hanpaopao <510423039@qq.com> Date: Sun, 16 Feb 2025 13:02:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Files/DownloadFileObjectInput.cs | 9 +++++++++ .../Files/IFileAppService.cs | 6 ++++++ ...on.AbpPro.FileManagement.Application.Contracts.csproj | 1 + .../Files/FileAppService.cs | 7 +++++++ .../Files/FileController.cs | 7 +++++++ .../Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs | 1 - 6 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/DownloadFileObjectInput.cs 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)) {