Answer the question
In order to leave comments, you need to log in
React js. ASPNET Core 3.1. Where to save uploaded images and how to display them on the site from the storage location if there is a Redirect in React?
You need to save the user's images somewhere, I read a lot of different things and came to the conclusion that it's better in the wwwroot folder.
Storing images in a database: pros and cons
Uploading files to the server
How to save image on the server using ASP.NET Core 2.0
But I can't display an image that is saved in a folder.
Startup.cs
-
public void Configure(IApplicationBuilder app)
{
app.UseHttpsRedirection();
// For the wwwroot folder
string cachePeriod = _env.IsDevelopment() ? "600" : "604800";
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = ctx =>
{
ctx.Context.Response.Headers.Append("Cache-Control", $"public, max-age={cachePeriod}");
},
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", "static")),
RequestPath = "/static"
});
}
<img src="~/static/placeholder.png" alt="Placeholder" class="thumb">
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question