0

The filecmp.cmp() method takes two arguments, path of file1 and path of file2. InMemoryUploadedFile objects won't have any path associated with them. So, what is the simplest method to compare two InMemoryUploadedFile objects?

Thanks

Rbk
  • 1
  • 3

1 Answers1

0

You will have to store the file somewhere on the server and do the comparison.

you can refer to the documentation https://docs.djangoproject.com/en/3.2/topics/http/file-uploads/#basic-file-uploads

after the comparison, you can either store the file or delete it.

  • Thank you for answering. Is it the only way? or other than filecmp, is there any way we can compare files? – Rbk Jun 08 '21 at 06:10
  • this is the only way and the straightforward way to do it if you want to compare the file using filecmp, if you don't want to use filecmp, you can calculate the file hash of both files and compare them. – Sreevardhan Reddy Jun 08 '21 at 06:23