Preventing duplicate files in a SQL Server 2014 FileTable

556 views Asked by At

I'm planning to write a ASP.NET MVC app that will upload large files (possibly as large as 500 MB) to a SQL Server 2014 FileTable. Is there some way to check if the file already exists in the FileTable before uploading?

If the file already exists in the database, then I will want to reference the already-uploaded file instead of uploading a new one.

If the file must first be uploaded to the FileTable before checking whether the file already exists in the FileTable, what's the recommended way to do the comparison? (Should I do some sort of separate CRC generated for each file and then compare against that?)

Thanks!

1

There are 1 answers

0
Ian Boyd On

You will have to calculate the hash of the file on the client side before uploading it. I don't have the pieces of code, only the concepts:

  • using the HTML File API, and the File Reader to read the file
  • with a Javascript implementation of SHA256 compute the hash of the file
  • on your server you store the file contents, as well as the SHA256 hash of each file
  • client performs an AJAX request to see if the a file with this hash already exists
  • if it doesn't already exist: Upload it!