selvi jp

selvi jp

  • NA
  • 323
  • 76.8k

Upload image on folder and path stored in DB in core api

Jun 29 2021 5:26 AM

Here i can upload image but I want to upload image without webHostEnvironment.WebRootPath in CORE API

private string UpdateUploadedFile(profileImg model)
        {
            string uniqueFileName = null;

            if (model.profile_imagePath != null)
            {

                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");

                uniqueFileName = "profile" + "_" + model.profile_imagePath.FileName;

                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.profile_imagePath.CopyTo(fileStream);
                }
            }
            return uniqueFileName;
        }


Answers (1)