I have a model in my web API class.
public class InspectionPhoto
{
public int Id { get; set; }
public int InspectionId { get; set; }
public int CategoryId { get; set;}
public string Employee { get; set; } = "DUMMYEMP";
public byte[] Data { get; set; }
}
I am building a corresponding model in my Angular client app.
export class InspectionPhoto
{
public Id: number;
public InspectionId: number;
public CategoryId: number;
public Employee: string;
public Data: Blob;
}
Angular code to call the service. This is currently hard-coded for testing.
public callwebapi(event)
{
console.log('welcome to callwebapifunction');
console.log(event);
//var jsonIn = document.getElementById("mytext").innerText;
var jsonIn = '{"Id": -1, "InspectionId": 95, "CategoryId": 9, "Employee": "Golly Goblin", "Data":"iVBORw0KGgoAAAANSUhEUgAAASwAAABkCAIAAACzY5qXAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAAR5JREFUeF7t0zEBAAAMw6D5N93JyAMeuAEpCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhJiEEJMQYhJCTEKISQgxCSEmIcQkhNT26WBE8+9D0NEAAAAASUVORK5CYII"}';
console.log(jsonIn);
const uri = 'https://localhost:44304/api/values';
let header = new HttpHeaders();
header.set('Access-Control-Allow-Origin','*');
header.append('Content-Type', 'application/json;charset=UTF-8');
header.append('accept', 'application/json');
try{
console.log('trying httpPost');
this.http.post<InspectionPhoto>(uri, jsonIn, {headers: header}).subscribe();
}catch{
console.log('i am in catch block');
}
}
I am getting this exception thrown:
Exception thrown: 'System.FormatException' in mscorlib.dll
Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in Newtonsoft.Json.dll
What data type will actually map to a byte array? Is it blob or Image? I am not able to get either to work correctly.
The api works as soon as I drop the Data from both models, but my requirement is to send an image.
Thanks You!