how to upload image to sql database

Mar 15 2021 2:11 AM
Hi everyone, i am developing a web api i want to upload image to sql database.
 
  1. so far i know first i have to convert image in to byte array 
  2. i have created a coloum of type varbinary
  3. model with data type byte[];
  4. but when i pass the image from postman app IN object its showing null
Here i have attached my code 
 
public class User_details
{
[Key]
public Guid user_id { get; set; }
public string First_name { get; set; }
public string Middle_name { get; set; }
public string Last_name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public DateTime Dob { get; set; }
public string Role { get; set; }
public DateTime Created_on { get; set; }
public Boolean Verification { get; set; }
public string Password_reset_OTP { get; set; }
public byte Profile_pic { get; set; }
}
controller
 
Contextclass contextclass = new Contextclass();
[System.Web.Http.HttpPost]
public HttpResponseMessage signup([FromBody] User_details userdetails)------>to here im not getting the image
{
try
{
using(Contextclass contextclass=new Contextclass())
{
var mailverification = emailexits(userdetails.Email);
if(mailverification)
{
return Request.CreateResponse(HttpStatusCode.NotFound, "email_already_exits");
}
userdetails.user_id = Guid.NewGuid();
userdetails.Verification = false;
userdetails.Created_on = DateTime.Now.Date;
user_registration user_Registration = new user_registration();
user_Registration.userregistration(userdetails);
senduserverificationmail(userdetails.Email, userdetails.user_id);
var message = Request.CreateResponse(HttpStatusCode.Created);
return message;
}
}
catch(Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
 
if anybody help it will be really appreciated
Thanks in advance. 
 
Thank you 
Preetham hd 
 

Answers (3)