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
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With