Results 1 to 16 of 16

Thread: Which is the best place to store images?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70

    Which is the best place to store images?

    Hi !

    I want to store images, but I don’ t know which is the best place to store them.
    I have two cases:

    Case 1 (a few images) :
    I have 100 permanent images, jpg’ s and gif’s (from 10 kb to 30 kb) to display in some cases on the page depending on the user selections.

    Case 2 (images uploaded by the users) :
    On the page the users will be able to upload images (from 800 kb to 3.000 kb), and later these images will be displayed in another page.
    The file of these images will grow always, and it could be 5.000, 60.000 or 25.000.000 of images.

    I am considering to store all the images (in both cases) into a Sql database, and then querying the DB when I need to display these images or pictures.

    Which are your opinions and suggestions?

    Thanks,
    Cesar

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Store them as files on the drive. I wouldn't store static content in a database.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    I have to agree with Jamie.

    Don't store your images in a Blob field. They are a pain in the bot.
    Store the images in a folder somwhere and have a field in a table somewhere which will hold the images location and name.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70
    Ok thanks, I think this is a very good system.

    But I have a question, the physical file that I need to create will store images of many users, and every image (one or more) will belong to an offer. Then, what happens if some images have the same name?

  5. #5
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    You will have to check to see if a file already exists with that name already or you could always name the files being uploaded yourself.

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well seperate them out. For example :

    \root\images\username\*.*
    so...
    \root\images\plenderj\me.jpg
    \root\images\plenderj\you.jpg
    \root\images\venerable bede\me.jpg
    \root\images\meh\bleh.gif
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70
    But in my case one user can has several product images with the same name, because a user can publish several offers with the same product image. I mean, in my case the only thing that is unique is the offer_id (offer number), every offer has to have different images name if the offer has several images, but different offers can have identical images names.

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well then use the offerid in the path?

    \root\images\username\offerid_imagename.jpg
    or
    \root\images\offerid\username\imagename.jpg
    or
    \root\images\username\offerid\imagename.jpg
    or
    \root\images\offerid\username_imagename.jpg

    ... whatever works for you ...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70
    Ok, then I think that the best choice for me would be:

    \root\images\offerid_imagename.jpg

    I don' t need the user file, because in the database every offer has its user_id.
    I suppose that the 'root' file is a good physical place to store this kind of data..

  10. #10
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You could also use a GUID for the filename...

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70
    How I could use a GUID to store an image name?

    Maybe it is better to store the offer_id (bigint) followed by the image name.. Do you think that it would be better to use a GUID?

  12. #12
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Not a matter of better, just choice.

    I was noting it for others that may read your post months from now with a similiar question.
    VB Code:
    1. MyFileName As String = Guid.NewGuid.ToString

  13. #13
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    A GUID is definitely a good idea. I might try that myself in some projects
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Barcelona
    Posts
    70
    Ok, thank you!

  15. #15
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    We are storing images in the database and so far I dont see any problems. It also allows you to manage it in one place: no file storage on the HD, no pointers to the filename in the database.

  16. #16
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Other than every now and then, everyone's pictures on my page have red x's instead of pictures... (btw kidding)
    Last edited by nemaroller; Jul 27th, 2004 at 03:56 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width