Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access image from Web API Core Folder from Browser

How can access image from folder from web api core? I am doing as below

https://localhost:44344/Uploaded_Documents/IMG_20190314_205925_3be1d2b3-3bac-4184-8468-995d58d5ff80.jpg

But it is giving below error.

enter image description here

Me configuration is like below.

enter image description here

Image path is like below. enter image description here

How can I access this image from browser in web api core ?

like image 375
GOPAL SHARMA Avatar asked Dec 18 '22 17:12

GOPAL SHARMA


1 Answers

If you would like to access your file out of wwwroot folder,you need to configure the Static File Middleware as follows:

app.UseStaticFiles();// For the wwwroot folder

app.UseStaticFiles(new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(
                Path.Combine(Directory.GetCurrentDirectory(), "Uplodaed_Documents")),
            RequestPath = "/Uplodaed_Documents"
        });
//Enable directory browsing
app.UseDirectoryBrowser(new DirectoryBrowserOptions
        {
            FileProvider = new PhysicalFileProvider(
                Path.Combine(Directory.GetCurrentDirectory(), "Uplodaed_Documents")),
            RequestPath = "/Uplodaed_Documents"
        });

app.UseMvc();

You could refer to asp.net core static files Serve files outside of web root

like image 127
Ryan Avatar answered Mar 10 '23 03:03

Ryan