I have a list of colors, with textures that I want to show to particular users, so I need to load the image of the colors that a particular user has, the color's information is contained in a ObjecDTO and one of the properties is its image path. My question is how should I store the image path in the database, are there any special rules, for example since the database and the image file are on the same server should I store a complete file URL, or a relative url, what characters should I escape etcetera, or are there better approaches than mine?
I've searched the web but mostly point to storing BLOBs in the database, which I've found to be a bad practice.
Any guidance is really appreciated.
regards Tristian.
Create a column called: image_path VARCHAR(255) NOT NULL
And it would contain data like this:
~/images/image1.jpg
I would really suggest to store relative paths and put the remaining as a config. That way, you can migrate more easily. For the datatype, I suggest something along the line of varchar(255) and ensure that restriction in your code.
And don’t forget to set it as UTF-8 if it’s a user field
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