Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc 3: best way manage a model with an image

I'm trying to find the best way to manage a model with an associated image.

I don't know if is better to persiste the image in data store

class MyModel {
  ...
  public byte[] ImageData { get; set; }
  ...
}

or save the Url and upload the image to filesystem

class MyModel {
  ...
  public string ImageUrl { get; set; }
  ...
}

The essential thing is that I want manage the image in when I'm creating or editing the model record.

I don't want a dedicated model/view/controller aimed to upload/persist the image to the server. I want manage the imaged linked to a specific entity in the db.

Regards, Giacomo

like image 379
gsscoder Avatar asked Nov 13 '22 06:11

gsscoder


1 Answers

Your first approach is fine because you're storing the image in the database. You will still need a helper function of some sort which generates a URL to a handler which renders/displays the image.

You could choose to also store the image url in which case you wouldn't necessarily need a helper method.

If you would be storing images outside the database (e.g. on the filesystem) you wouldn't need the ImageData byte field obviously...

like image 56
Ropstah Avatar answered Dec 09 '22 18:12

Ropstah