down vote
favorite
I want to save image path in the database, I am using string type image not save in folder but image name also saved in the database. I am using string so SaveAs giving an error.
why I am using string? because when I am using public httppostfilebase image file {get;set;} show null value in controller .
imagePath: this variable contains string bytes image file: this variable contains the name of the image
I am not getting any error but the problem in the last line of code how to save in a folder. i am using string but SaveAs not working save as work only Httppostfilebase. in this scenario How to save
Any expert here to resolve my issue, and tell me what is the problem in my code.
What I have tried:
Model
public string imagePath { get;set; }
public string imageFile { get;set; }
C#
byte[] data = Convert.FromBase64String(Quot[i].imageFile.Replace("data:image/jpeg;base64,", ""));
Image img;
MemoryStream ms = new MemoryStream(data, 0, data.Length);
ms.Write(data, 0, data.Length);
img = Image.FromStream(ms, true);
string fileName = Path.GetFileNameWithoutExtension(Quot[i].imagePath);
string extension = Path.GetExtension(Quot[i].imagePath);
fileName = fileName + DateTime.Now.ToString("dd/MM/yyyy") + extension;
Quot[i].imagePath = "~/AppFiles/Images/" + fileName;
fileName = Path.Combine(HttpContext.Current.Server.MapPath("~/AppFiles/Images/"), fileName);
Quot[i].imageFile.SaveAs(fileName);