Saving a base64 string as an image into a folder on server using C# and Web Api
In Base64 string You have all bytes of image. You don't need create Image
object. All what you need is decode from Base64 and save this bytes as file.
Example
public bool SaveImage(string ImgStr, string ImgName)
{
String path = HttpContext.Current.Server.MapPath("~/ImageStorage"); //Path
//Check if directory exist
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path); //Create directory if it doesn't exist
}
string imageName = ImgName + ".jpg";
//set the image path
string imgPath = Path.Combine(path, imageName);
byte[] imageBytes = Convert.FromBase64String(ImgStr);
File.WriteAllBytes(imgPath, imageBytes);
return true;
}