how can you compare uploaded files in the same django model?

I would not suggest both of these approaches. Why?

  1. Because multiple users may upload files with same name. Even same user can upload it multiple times with same name (So many users simply upload Untitles.xlsx.

  2. Every time a file is uploaded, it is stored in a temporary location for the GET dictionary (try /tmp on linux). So your temporary name/location may be different if the same named file exists.

  3. The intention might be to reupload the same file. In that case you might want to update.

So a safer option would be to get the checksum of the file (md5/sha1/sha256) and even store that in the database. That will tell you if the file is indeed the same. You can check the currently uploaded file for checksum.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top