I want to send image to api end point and end point accept byte[] how can i handle this. My code is: ReactJS function on upload button click:
let onClickHandler = () => {
let data = new FormData()
data.append('file', image);
axios.post("/Contact/ContactForm/", {
AttachedImage: data
}, {
headers: {
'Content-Type': 'multipart/form-data',
'X-Requested-With': 'XMLHttpRequest',
}
// receive two parameter endpoint url ,form data
})
.then(res => { // then print response status
console.log('binary Response......',res.statusText)
});
}
and my endpoint controller method:
[HttpPost]
public async Task<IActionResult> ContactForm([FromBody] Contact model)
{
try
{
model.CreationDate = DateTime.Now;
await _contact.ContactForm(model);
return Ok("Submitted Successfully");
}
catch (Exception ex) { return this.BadRequest("Not Submitted Successfully" + ex.ToString()); }
}
and finally Model.cs Class
public byte[] AttachedImage { set; get; }