Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 779173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:53:10+00:00 2026-05-14T19:53:10+00:00

I got many, many files to be uploaded to the server, and I just

  • 0

I got many, many files to be uploaded to the server, and I just want a way to avoid duplicates.

Thus, generating a unique and small key value from a big string seemed something that a checksum was intended to do, and hashing seemed like the evolution of that.

So I was going to use hash md5 to do this. But then I read somewhere that “MD5 are not meant to be unique keys” and I thought that’s really weird.

What’s the right way of doing this?

edit: by the way, I took two sources to get to the following, which is how I’m currently doing it and it’s working just fine, with Python 2.5:

import hashlib

def md5_from_file (fileName, block_size=2**14):
    md5 = hashlib.md5()
    f = open(fileName)
    while True:
        data = f.read(block_size)
        if not data:
            break
        md5.update(data)
    f.close()
    return md5.hexdigest()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:53:11+00:00Added an answer on May 14, 2026 at 7:53 pm

    Sticking with MD5 is a good idea. Just to make sure I’d append the file length or number of chunks to your file-hash table.

    Yes, there is the possibility that you run into two files that have the same MD5 hash, but that’s quite unlikely (if your files are decent sized). Thus adding the number of chunks to your hash may help you reduce that since now you have to find two files the same size with the same MD5.

    # This is the algorithm you described, but also returns the number of chunks.
    new_file_hash, nchunks = hash_for_tile(new_file)
    store_file(new_file, nchunks, hash)
    
    def store_file(file, nchunks, hash):
      "" Tells you whether there is another file with the same contents already, by 
         making a table lookup ""
      # This can be a DB lookup or some way to obtain your hash map
      big_table = ObtainTable()
    
      # Two level lookup table might help performance
      # Will vary on the number of entries and nature of big_table
      if nchunks in big_table:
         if hash in big_table[hash]:
           raise DuplicateFileException,\
             'File is dup with %s' big_table[nchunks][lookup_hash]
      else:
        big_table[nchunks] = {}
    
      big_table[nchunks].update({
        hash: file.filename
      })
    
      file.save() # or something
    

    To reduce that possibility switch to SHA1 and use the same method. Or even use both(concatenating) if performance is not an issue.

    Of course, keep in mind that this will only work with duplicate files at binary level, not images, sounds, video that are “the same” but have different signatures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got many files that I want to store in a single archive file.
Hy, suppose you got many files in a folder and you want first to
After pre-compiled a ASP.NET web site, I got many files with the names like
I've got a program (LAMMPS, as it happens) spanning many .cpp/.h files, all of
Situation: I have many gzipped input files that I want to process in a
I got many .dll files for my project. It is quite troublesome that moving
Do you know best way to upload too many files to Azure Blob container?
I've got many files with variables in them like {$var1} some text {$var2} some
I compiled a C project using the NDK and got many .a files which
I accidentally added many files (test files) which I do not want them to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.