I want to use the same controller action to save data and attachments i.e. profile pictures.
I added a prop to my model resource with IFormFile
datatype,
public IFormFile UserAvatarImage { get; set; }
I am using angular for front-end, I add the uploaded file to my model before I post it to the controller,
My controller model validation keeps giving me invalid input for UserAvatarImage
property. I know its a Json.NET deserialization error.
I tried to work around it as mentioned here, using model binding but did not work either,
I also tried to change the property from IFormFile
to object
and then using file stream reader but did not work too,
var file = model.UserAvatarImage as IFormFile;
string fileContent = null;
using (var reader = new StreamReader (file.OpenReadStream ())) {
fileContent = reader.ReadToEnd ();
}
var result = JsonConvert.DeserializeObject<IFormFile> (fileContent);
any other suggestion?