When I tried to add the image as binary into my database, using ASP.NET Web API 2 using Entity Framework. I'm getting this error:
The request entity's media type 'multipart/form-data' is not supported for this resource
This is the code which I tried:
[HttpPost]
public IHttpActionResult ImageUpload(HttpPostedFileBase postedFile)
{
byte[] bytes;
using (BinaryReader br = new BinaryReader(postedFile.InputStream))
{
bytes = br.ReadBytes(postedFile.ContentLength);
}
SchoolContext context = new SchoolContext();
context.Images.Add(new Image
{
Name = Path.GetFileName(postedFile.FileName),
ContentType = postedFile.ContentType,
ImageBinary = bytes
});
context.SaveChanges();
return Ok(new { messages = "Image uploaded!" });
}