when i save image, image save successfully in database, but it takes full image path like this C:\Users....\Uploads\employee.jpg i dont want like this, i need to save image path somehting like this ~Uploads\employee.jpg and in specific folder and same path should save in database, also if someone show me after saving correct path how i can view that image. there is error i get because of this:
"Not allowed to load local resource :file:///C:/......"
thank you!
my code:
[HttpPost]
public async Task<IActionResult> Create(Photos photos)
{
if (ModelState.IsValid)
{
var filePath =
Path.Combine(_appEnvironment.ContentRootPath,
"Uploads", photos.FormFile.FileName);
photos.PhotoPath = filePath;
using (var stream = new FileStream(filePath, FileMode.Create))
{
await photos.FormFile.CopyToAsync(stream);
}
_context.Add(photos);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["NewsId"] = new SelectList(_context.News, "NewsId",
"NewsBigTitle", photos.NewsId);
return View(photos);
}