add:
更新
This commit is contained in:
@@ -7,6 +7,7 @@ using IM_API.Models;
|
||||
using IM_API.Tools;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using StackExchange.Redis;
|
||||
using System.Text;
|
||||
@@ -42,7 +43,9 @@ namespace IM_API
|
||||
});
|
||||
|
||||
builder.Services.AddRabbitMQ(configuration.GetSection("RabbitMqOptions").Get<RabbitMQOptions>());
|
||||
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
builder.Services.AddAllService(configuration);
|
||||
|
||||
builder.Services.AddSignalR().AddJsonProtocol(options =>
|
||||
@@ -134,6 +137,23 @@ namespace IM_API
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
string uploadPath = Path.Combine(Directory.GetCurrentDirectory(), "Uploads","files");
|
||||
|
||||
// 2. 如果文件夹不存在则创建,防止程序启动报错
|
||||
if (!Directory.Exists(uploadPath))
|
||||
{
|
||||
Directory.CreateDirectory(uploadPath);
|
||||
}
|
||||
|
||||
// 3. 配置静态文件映射
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
// 指定物理磁盘路径
|
||||
FileProvider = new PhysicalFileProvider(uploadPath),
|
||||
// 指定浏览器访问的虚拟前缀(例如:http://localhost:5000/files/1.jpg)
|
||||
RequestPath = "/uploads/files"
|
||||
});
|
||||
|
||||
app.UseCors();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
Reference in New Issue
Block a user