I am doing some work with storing members photos in the database and I am wondering whether I should store photo paths like this:
http://www.domain.com/path/to/photo
or like this
/path/to/photo
Specifically, I am concerned with the fact that I now have 1 server, but over time, I will have more than one, and down the line I might have a CDN serve up the photos. What is the good-practice way of storing the paths for the long term?
Thanks!
Alex
This really comes down to personal preference.
If concise paths are important and indexing and searching won’t be completed on the column then store the whole thing (although note your first form still contains assumptions – what if you also server the photos through HTTPS – they each file has two paths).
If data size and normalization is important store just the largely changing part of the URL and assume the consistent part. If that changes over time, ALTER the table and make a one time UPDATE to append the existing assumed URL.
Finally physical storage and logical presentation can be two different things – using an MVC design you could have a controller that turns a requested
/path/to/myimage.jpgintocdn.example.com/myassets/0123/123122.jpg