I currently have a razor page that has a Uploader component (via Syncfusion) that calls an API whenever a file is uploaded. The API is responsible for renaming that file to the same name of the file that the UI is using inside of the wwwroot/assets folder, and rewriting whatever image data that the original image contains. The controller is not hit when I run in IIS, so I run the project using the API project associated with the Web Assembly project. This works exactly as expected and in my Web Assembly project, the image is replaced as it should be. The issue is is that in the UI, the image stays the same, and I think it has to do with the project I am running it on, which is the API project. However, the API project's wwwroot folder is located inside of the bin/net 5.0/6.0 folders.
This method is what I use to overwrite the image in the Web Assembly wwwroot folder. But because I am running from the API project, its hard to tell where the png is coming from.
[HttpPost("[action]")]
public void SaveLogo([FromForm] IEnumerable<IFormFile> UploadFiles)
{
try
{
foreach (var file in UploadFiles)
{
var filename = ContentDispositionHeaderValue
.Parse(file.ContentDisposition)
.FileName
.Trim('"');
filename = "KFNBOfficialLogo.png";
_hostingEnv.ContentRootPath = "C:\\Users\\user\\Desktop\\repos\\Manager\\Manager\\Manager\\wwwroot\\assets\\Logo.png";
filename = _hostingEnv.ContentRootPath;
using (FileStream fs = System.IO.File.Create(filename))
{
file.CopyTo(fs);
fs.Flush();
}
}
}
catch (Exception e)
{
Response.Clear();
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File failed to upload";
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message;
}
}
}