Skip to content

Commit

Permalink
feat: 添加下载文件接口
Browse files Browse the repository at this point in the history
  • Loading branch information
WangJunZzz committed Feb 16, 2025
1 parent 0adb292 commit 3c53840
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Lion.AbpPro.FileManagement.Files;

public class DownloadFileObjectInput
{
/// <summary>
/// 文件Id
/// </summary>
public Guid Id { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

Expand All @@ -25,4 +26,9 @@ public interface IFileAppService : IApplicationService
Task DeleteAsync(DeleteFileObjectInput input);

Task<GetFileObjectOutput> GetAsync(GetFileObjectInput input);

/// <summary>
/// 下载文件
/// </summary>
Task<FileContentResult> DownloadAsync(DownloadFileObjectInput input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" />
<PackageReference Include="Volo.Abp.Ddd.Application.Contracts" />
<PackageReference Include="Volo.Abp.Authorization" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -94,4 +95,10 @@ public async Task<GetFileObjectOutput> GetAsync(GetFileObjectInput input)
var file = await _fileObjectManager.GetAsync(input.Id);
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ public Task<GetFileObjectOutput> GetAsync(GetFileObjectInput input)
{
return _fileAppService.GetAsync(input);
}

[HttpPost("Download")]
[SwaggerOperation(summary: "下载文件", Tags = new[] { "Files" })]
public Task<FileContentResult> DownloadAsync(DownloadFileObjectInput input)
{
return _fileAppService.DownloadAsync(input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
// });

});
app.UseConfiguredEndpoints(endpoints => { endpoints.MapHealthChecks("/health"); });

if (configuration.GetValue("Consul:Enabled", false))
{
Expand Down

0 comments on commit 3c53840

Please sign in to comment.