I have created an ASP.NET web API which has a controller named ImageSaveController
. This has an InsertImage
method which inserts data into database and is an HttpPost
method. This method receives an object of type ImageData
as a parameter. The code for the controller and the parameter class are given below:
public class ImageSaveController : ApiController
{
[HttpPost]
public IHttpActionResult InsertImage(ImageData imageData)
{
System.Data.SqlClient.SqlConnection conn = null;
try
{
//Image save to database code here
}
catch (Exception ex)
{
return Content(HttpStatusCode.NotModified, ex.Message);
}
finally
{
if (conn != null)
conn.Close();
}
return Content(HttpStatusCode.OK,"");
}
}
//ImageData class
public class ImageData
{
public int Id { get; set; }
public byte[] ImageValue { get; set; }
}
I would like to test it from a client. As you can notice, the ImageValue
property of the ImageData
class is a byte
array. Not sure how to pass the C# class parameter to this method. Ideally I would like to pass the parameter as json
and I am not sure how to construct the json
for this purpose. I am also not sure whether it could be tested using the chrome app called postman.