首页 > 其他分享 >WebAPI如何提供下载文件功能

WebAPI如何提供下载文件功能

时间:2022-11-29 14:33:45浏览次数:59  
标签:WebAPI 文件 功能 builder new 下载

提问

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

标签:WebAPI,文件,功能,builder,new,下载
From: https://www.cnblogs.com/wuhailong/p/16935319.html

相关文章