2

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?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.