Browse Source

feat: 添加下载文件接口

feat/cap 9.0.6.7
Hanpaopao 1 year ago
parent
commit
3c538400ca
  1. 9
      aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/DownloadFileObjectInput.cs
  2. 6
      aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/IFileAppService.cs
  3. 1
      aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Lion.AbpPro.FileManagement.Application.Contracts.csproj
  4. 7
      aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application/Files/FileAppService.cs
  5. 7
      aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.HttpApi/Files/FileController.cs
  6. 1
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs

9
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
{
/// <summary>
/// 文件Id
/// </summary>
public Guid Id { get; set; }
}

6
aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Files/IFileAppService.cs

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
@ -25,4 +26,9 @@ public interface IFileAppService : IApplicationService
Task DeleteAsync(DeleteFileObjectInput input); Task DeleteAsync(DeleteFileObjectInput input);
Task<GetFileObjectOutput> GetAsync(GetFileObjectInput input); Task<GetFileObjectOutput> GetAsync(GetFileObjectInput input);
/// <summary>
/// 下载文件
/// </summary>
Task<FileContentResult> DownloadAsync(DownloadFileObjectInput input);
} }

1
aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application.Contracts/Lion.AbpPro.FileManagement.Application.Contracts.csproj

@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" />
<PackageReference Include="Volo.Abp.Ddd.Application.Contracts" /> <PackageReference Include="Volo.Abp.Ddd.Application.Contracts" />
<PackageReference Include="Volo.Abp.Authorization" /> <PackageReference Include="Volo.Abp.Authorization" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" /> <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" />

7
aspnet-core/modules/FileManagement/src/Lion.AbpPro.FileManagement.Application/Files/FileAppService.cs

@ -1,5 +1,6 @@
using Lion.AbpPro.FileManagement.Provider; using Lion.AbpPro.FileManagement.Provider;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Lion.AbpPro.FileManagement.Files; namespace Lion.AbpPro.FileManagement.Files;
@ -94,4 +95,10 @@ public class FileAppService : ApplicationService, IFileAppService
var file = await _fileObjectManager.GetAsync(input.Id); var file = await _fileObjectManager.GetAsync(input.Id);
return ObjectMapper.Map<FileObjectDto, GetFileObjectOutput>(file); return ObjectMapper.Map<FileObjectDto, GetFileObjectOutput>(file);
} }
public async Task<FileContentResult> DownloadAsync(DownloadFileObjectInput input)
{
var file = await _fileObjectManager.GetAsync(input.Id);
return new Microsoft.AspNetCore.Mvc.FileContentResult(file.Bytes, file.ContentType);
}
} }

7
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); return _fileAppService.GetAsync(input);
} }
[HttpPost("Download")]
[SwaggerOperation(summary: "下载文件", Tags = new[] { "Files" })]
public Task<FileContentResult> DownloadAsync(DownloadFileObjectInput input)
{
return _fileAppService.DownloadAsync(input);
}
} }

1
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)) if (configuration.GetValue("Consul:Enabled", false))
{ {

Loading…
Cancel
Save