I'm developing a Blazor server application and I'm trying to implement imagesharp.web (V.3.01)
I have to use a folder called "Uploads" (not inside wwwroot). I'm trying to use PhysicalFileSystemProviderOptions, setting the ProviderRootPath to the desired folder, but it is not working.
Can anyone help on this problem?
var pathToUploads = Path.Combine(Directory.GetCurrentDirectory(), "Uploads");
var pathToUploadsCache = Path.Combine(Directory.GetCurrentDirectory(), "Uploads", "is-cache");
builder.Services.AddImageSharp(options =>
{
options.BrowserMaxAge = TimeSpan.FromDays(7);
options.CacheMaxAge = TimeSpan.FromDays(365);
}).ClearProviders()
.AddProvider<WebRootImageProvider>()
.Configure<PhysicalFileSystemCacheOptions>(options =>
{
options.CacheRootPath = null;
options.CacheFolder = pathToUploadsCache;
options.CacheFolderDepth = 8;
})
.SetCache<PhysicalFileSystemCache>()
.AddProvider<PhysicalFileSystemProvider>()
.Configure<PhysicalFileSystemProviderOptions>(options=>
{
options.ProviderRootPath = pathToUploads;
});
var app = builder.Build();
// Set Uploads folder
SD.ContentRootPath = app.Environment.ContentRootPath;
SD.UploadsFullServerPath = Path.Combine(app.Environment.ContentRootPath, configuration["UploadsFolder:Name"]);
SD.UploadsRequestPath = configuration["UploadsFolder:WebPath"];
SD.UploadsNameOnly = configuration["UploadsFolder:Name"];
SD.UploadsRootFolderName = configuration["UploadsFolder:RootFolderName"];
SD.UploadsRootFolderWebPath = configuration["UploadsFolder:RootFolderWebPath"];
app.UseImageSharp();
app.UseStaticFiles();
if (!Directory.Exists(SD.UploadsFullServerPath)
|| !Directory.Exists(Path.Combine(SD.UploadsFullServerPath, SD.UploadsRootFolderName)))
{
Directory.CreateDirectory(Path.Combine(SD.UploadsFullServerPath, SD.UploadsRootFolderName));
}
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(builder.Environment.ContentRootPath, SD.UploadsNameOnly)),
RequestPath = SD.UploadsRequestPath
});