Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use multiple folder into app.UseStaticFiles in .net core?

I want to get access to multiple folder locations from my web api to display image. I can't change the folder locations (depending on devices on which I don't have right to modify anything).

for one of the folders I did:

string FolderToListen = Configuration["xxx:yyy"];

app.UseStaticFiles(new StaticFileOptions()
{
    FileProvider = new PhysicalFileProvider(FolderToListen),
});

and now I would like to do:

string FolderToListen2= Configuration["xxx2:yyy2"];
app.UseStaticFiles(new StaticFileOptions()
{
    FileProvider = new PhysicalFileProvider(FolderToListen),
    FileProvider = new PhysicalFileProvider(FolderToListen2),
});

but it doesn't work. Is there any way to pass multiple folders to UseStaticFiles ?

like image 687
p.deman Avatar asked May 02 '19 15:05

p.deman


People also ask

How can add wwwroot folder in ASP.NET Core API?

In order to add the wwwroot folder, right-click on the project and then select add => new folder option and then provide the folder name as wwwroot.

How do I put files in a folder in .NET Core?

First, the File is read as Binary Data into a Byte Array object using the ReadAllBytes method of the File class. And then the Byte Array object is sent for download using the File function. //Fetch all files in the Folder (Directory). string[] filePaths = Directory.

Where do I put static files in NET Core?

Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed with the UseWebRoot method. For more information, see Content root and Web root.


1 Answers

You can register UseStaticFolder twice:

app.UseStaticFiles(new StaticFileOptions()
{
    FileProvider = new PhysicalFileProvider(FolderToListen),
});

app.UseStaticFiles(new StaticFileOptions()
{
    FileProvider = new PhysicalFileProvider(FolderToListen2),
});
like image 138
meziantou Avatar answered Oct 23 '22 00:10

meziantou