Reputation: 7291
Here is my action method in asp.net mvc project-
[HttpPost]
public ActionResult UploadSignatureTwo(String imageString)
{
byte[] bytes = Convert.FromBase64String(imageString);
Image img;
using (MemoryStream ms = new MemoryStream(bytes))
{
img = Image.FromStream(ms);
}
img.Save(path,ImageFormat.Jpeg); //in app_data folder, has write permission.
}
Sample content of imageString:
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wB .....
Why I'm getting that exception - A generic error occurred in GDI+
?
Upvotes: 4
Views: 1175
Reputation: 926
var bytes = Convert.FromBase64String(image);
using (var imageFile = new FileStream(Path.Combine(path,"test.jpeg"), FileMode.Create))
{
imageFile.Write(bytes, 0, bytes.Length);
imageFile.Flush();
}
Upvotes: 2