Guest User

Guest User

  • Tech Writer
  • 611
  • 128.1k

Upload image in asp.net core.

Oct 6 2020 8:42 AM
I  have use this code for upload image file .Upload images suessfully but i have face issue this image show only local server not show live server.What's error please let me know 
string filePath = Path.GetExtension(obj_Parameter.EducationalImage.FileName);
if (filePath == ".jpg" || filePath == ".png" || filePath == ".jpeg" || filePath == ".jpe" || filePath == ".jif" || filePath == ".webp")
{
var wwwrootPath = webHost.ContentRootPath + "\\wwwroot\\Uploads\\";
string thisFileName = Path.Combine(obj_Parameter.EducationalImage.FileName);
//if (obj_Parameter.EducationalImage?.Length > 0)
//{
filePath = Path.Combine(wwwrootPath, obj_Parameter.EducationalImage.FileName);
using FileStream fileStream = new FileStream(filePath, FileMode.Create);
{
await obj_Parameter.EducationalImage.CopyToAsync(fileStream);
}
//}
obj_education.Title = obj_Parameter.Title;
obj_education.Description = obj_Parameter.Description;
obj_education.ImagePath = thisFileName;
obj_education.IsActive = true;
obj_education.IsDeleted = false;
obj_education.EducationImageCategoryId = obj_Parameter.EducationImageCategoryId;
obj_education.UpdatedDate = DateTime.UtcNow;
obj_education.ImageStatus = 0;
obj_education.IsFavStatus = false;
await _context.TblEducationalVideo.AddAsync(obj_education);
await _context.SaveChangesAsync();
 

Answers (2)