0

this is dring me nuts! I have a web app i have created using ASP .net core2. I have a registration page that allows a user to select an image file and this is working. I use this is my Model:

[Display(Name = "Face Image")]
Public IFormFile UserImageFile { get; set; }

In my AccountController class I have

  public async Task<IActionResult> Register(RegisterViewModel model, string returnUrl = null)
    {
        ViewData["ReturnUrl"] = returnUrl;
        if (ModelState.IsValid)
        {
            var imageBytes = GetByteArrayFromImage(model.UserImageFile);
            var user = new ApplicationUser { UserName = model.Email, Email = model.Email, UserImage = imageBytes};
            user.UserImage = imageBytes;
            var result = await _userManager.CreateAsync(user, model.Password);

This all seems to work. If I debug and look at the user, I can see that UserImage has a byte array. All seems ok BUT the field in the database isnt getting the value. Is there a step I have to add somewhere that is hidden to set this value on the database?

4
  • If you are facing that issue (You are not experienced on that), using a BLOB will probably be a better approach. You'll avoid many complications. If you still want to use that, tell us what is your column type? Is it SQLServer? Commented Apr 13, 2018 at 15:12
  • The table is AspNetUsers and I have tried column type Image and now var binary max [UserImage] VARBINARY (MAX) NULL Commented Apr 13, 2018 at 15:20
  • will varbinary(Max) take a byte array? Commented Apr 13, 2018 at 15:42
  • got it for that part..I hadnt added {get; set;} doh! will re test Commented Apr 13, 2018 at 16:27

1 Answer 1

1

ok so I was so very close to having it right! All I was missing was the {get; set;}! for my new field definition in ApplicationUser. now it works perfect

Sign up to request clarification or add additional context in comments.

Comments

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.