ASP.NET - Duplicate image upload to SQL Server database

Discussion in 'C#' started by nickjason, Aug 5, 2009.

  1. #1
    Hi All,
    I am uploading images to SQL Server 2005 using asp.net. The database table has a binary field, image length field,file path field and a field for the file type.

    The issue is that the user is able to upload the same image to the database using different file names.

    What unique property should I check for to prevent duplicate images from being uploaded. I tried checking the file length but two different images can have the same length, so this prevented a new image from being uploaded.

    Anyone has any idea?
     
    nickjason, Aug 5, 2009 IP
  2. textbox

    textbox Guest

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What type of an application is this that you do not want to images to be the same?
     
    textbox, Aug 5, 2009 IP
  3. mfawn

    mfawn Active Member

    Messages:
    573
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #3
    I'm not sure if that is even possible because I think once you rename the file it changes the image code so I don't know if there would be anything you could match.
     
    mfawn, Aug 5, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Hi, assuming that you are storing the image in a field in the database, just find any fields that are the same length in bytes as the inputted file... if one exists, compare the bytes of the file to the bytes within the database, if they are the same then you have a duplicate.
    If you want some sample code let me know.
     
    camjohnson95, Aug 14, 2009 IP
  5. SlitheryImp

    SlitheryImp Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You could compare the MD5 hash of the images:
    h**p://bytes.com/topic/visual-basic-net/answers/372658-getting-md5-hash-image-file
     
    SlitheryImp, Aug 28, 2009 IP