WebAPI如何提供下载文件功能

提问

WebAPI如何提供下载文件功能

回答

//开启目录浏览服务
builder.Services.AddDirectoryBrowser();
//指定文件目录
app.UseFileServer(new FileServerOptions
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(builder.Environment.ContentRootPath, "wwwroot\\UploadFiles")),
    RequestPath = "/StaticFiles",
    EnableDirectoryBrowsing = true
});

参考

https://learn.microsoft.com/zh-cn/aspnet/core/security/cors?view=aspnetcore-7.0

posted @ 2022-11-29 14:28  喜爱糖葫芦  阅读(159)  评论(0编辑  收藏  举报