Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Silvija 58 posts 171 karma points
    Mar 16, 2019 @ 14:51
    Silvija
    0

    Avatar image upload failed

    I am working with member API and i am trying to upload the image when registering. After i register the member and open backoffice i see this: enter image description here

    Controller

    public class RegisterController : SurfaceController
    {
        // GET: Register
        public ActionResult Register(Models.RegisterModel model)
        {
            if (!ModelState.IsValid)
                return CurrentUmbracoPage();
    
            var memberService = Services.MemberService;
    
            if (memberService.GetByEmail(model.Email) != null)
            {
                ModelState.AddModelError("", "A member with that email alredy exists");
                return CurrentUmbracoPage();
            }
    
            var member = memberService.CreateMemberWithIdentity(model.Email, model.Email, model.Name, "bMEMembers");
    
            member.SetValue("companyName", model.CompanyName );
            member.SetValue("avatar", model.Avatar);
    
    
            memberService.SavePassword(member, model.Password);
            Members.Login(model.Email, model.Password);
    
            memberService.Save(member);
    
            return Redirect("/");
        }
    }
    

    Model

    public class RegisterModel
    {
        [Required]
        public string Name { get; set; }
    
        [Required]
        [EmailAddress]
        public string Email { get; set; }
    
        [Required]
        public string Password { get; set; }
    
        public string CompanyName { get; set; }
    
        public HttpPostedFileBase Avatar { get; set; }
    
        public string ExistingProfilePicture { get; set; }
    }
    

    View

     <fieldset>
        @Html.LabelFor(model => model.Name)
    
        @Html.EditorFor(model => model.Name)
    
        @Html.ValidationMessageFor(model => model.Name)
    
    
        @Html.LabelFor(model => model.Email)
    
        @Html.EditorFor(model => model.Email)
    
        @Html.ValidationMessageFor(model => model.Email)
    
    
        @Html.LabelFor(model => model.Password)
    
        @Html.PasswordFor(model => model.Password)
    
        @Html.ValidationMessageFor(model => model.Password)
    
    
        @Html.LabelFor(model => model.CompanyName)
        @Html.EditorFor(model => model.CompanyName)
        @Html.ValidationMessageFor(model => model.CompanyName)
    
        @Html.LabelFor(model => model.Avatar)
        <input type="file" name="Avatar" />
        @Html.ValidationMessageFor(model => model.Avatar)
    
        <input class="btn" type="submit" value="Create" />
    </fieldset>
    

    I am using Umbraco 8 and i followed tutorial from Umbraco TV

  • Silvija 58 posts 171 karma points
    Mar 18, 2019 @ 21:31
    Silvija
    0

    I have tried this code in umbraco v7 and it works.

    Nobody knows why is it not working in Umbraco 8?

  • David Christiansen 13 posts 163 karma points
    May 19, 2019 @ 15:11
    David Christiansen
    100

    I Just found the solution replace

    member.SetValue("avatar", model.Avatar);
    

    With

    member.SetValue(Services.ContentTypeBaseServices,"avatar", model.Avatar.FileName, model.Avatar);
    

    Remember to add:

    using Umbraco.Core;
    
  • Silvija 58 posts 171 karma points
    May 24, 2019 @ 17:38
    Silvija
    0

    Hi David,

    Thanks a lot its working great :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies