2

Hi there Im new with this ASP MVC5 with EF6. Currently I am working on a project that requires to save profile picture of a user. My model class is

    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }

    [Required]
    public String Email { get; set; }

    [Required]
    public String Password { get; set; }

    public String FirstName { get; set; }

    [Required]
    public String LastName { get; set; }

I am not sure how to add profile picture attribute here. The controller class and view is generated automatically by VS.

Update: I am thinking to save the profile picture in "physical files" instead of saving the "picture data" on database.

user2936719
  • 165
  • 2
  • 10
  • Saving pictures in database is not really good idea, It will increase size of database very fast. Better Idea is to manage them on file system by saving pictures by their Identifier and loading them on demand. – Rajnikant Jun 28 '15 at 13:27
  • @user2936719, If you want to save the file path in DB. Create a column in DB called ProfilePicPath as varchar data type. So the EF will create a model like public string ProfilePicPath {get; set;} – Golda Jun 29 '15 at 13:10

1 Answers1

1

To upload the picture to Azure you should use blob storage. Here is an answer how to do that Upload image to Azure blob storage Then you take the absolute URI for the image uploaded and save it to a string property of your model class mentioned in your question.

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }

[Required]
public String Email { get; set; }

[Required]
public String Password { get; set; }

public String FirstName { get; set; }

[Required]
public String LastName { get; set; }

[Required]
public String ImageUrl{ get; set; }
Community
  • 1
  • 1
Magnus Karlsson
  • 3,549
  • 3
  • 31
  • 57