SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is a good approach for storing multiple sized product images?

    The legacy e-commerce website I am working on at the moment uses the product id to name the image for each product. The image name and location are not stored in the database. So the product details page builds the product image name using the product id and reads it from the product folder.

    New requirements have come through where they want to have 6 alternate sizes and some alternate views of the product (0 - 4 alternate views). I am not sure the current technique will scale very well. Looking for files of alternate images would be a lot more expensive then reading file names from a database.

    The website is ASP .Net 2.0 and using SQL 2005.


    At the moment I am thinking about having a new table to store productid, image path and type. So each product can have multiple product images. Then I will have to introduce a range of types for the different sized images and different logic around fetching the right type from the database.
    What techniques do other sites use to multiple store images?

  2. #2
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You touched on one way, use the product tables id as the primary key, to match the foreign key on the child table, witch would store the path to multiple images.

    I would assume if you were to store, not sure if you thought of it, would to store the images in the database. But, with multiple images it would greatly tax your websites performance.

    I would go with the way you mentioned. Anyone else want to chime in?
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  3. #3
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I personally prefer storing image paths in a database and not the images themselves. Databases are for data and filesystems are for files!

    I agree with the child table approach, too. If could even have another table to store the types.

    Putting the images on a CDN service would be nice, too. Move some of that image traffic off of your server.

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,625
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Filesystems definitely handle files better in an absolute sense. But databases are not a horrible option, especially if file sizes are under 5 or 10mb. They have a few advantages -- mainly much easier to transport one big DB backup then lots of files strewn about the filesystem. You don't need to worry about filesystem security, and not as much about other things messing with your artifacts. Finally, you can take advantage of transactions to write things to the database. ACID typically isn't an option with filesystems . ..

    Insofar as CDNs and such go, that is still doable -- just use the database as the original, backed-up store and distribute stuff to the CDN and such as requested.

  5. #5
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the responses.

    I had been worried about over engineering the solution. It was good to hear others were thinking the same way I was. New database tables for image information and separate table for image type will allow me to handle all of the requirements.

    Don't think I will store the images in the database. It is something I had not thought of (which was what I had hoped for in asking this question, thanx!).
    Not sure our database server would be up to the extra load.

    A CDN would be cool. It is good to know that it can be scaled up if necessary. Just trying to get it working for now :P


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •