Search code examples
javascriptwebchecksumconsistent-hashing

Do I need to checksum the file at browser side then checksum and compare them at server side?


In my website , some important files will be uploaded, do I need to calculate the file's checksum with JavaScript at the browser side, then calculate again with golang and compare them at the server side to make sure the files got by server are consistent?


Solution

  • Currently i am developing javascript for uploading files. It is definitivly possible. You can put a webworker in your javascript and let it do the calculations.

    Webworker Info: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers

    I use crypto-js to calculate the checksums.

    Checksums: https://code.google.com/archive/p/crypto-js/

    Some problems can occur when the files you want to upload are large. In my case for example, files bigger then 40MB causes browser crashes or OutOfMemory-Exceptions. But if you try to upload small files, this maybe will work for you.

    To awnser your question. It is not neccesarry to compare checksums. But it is a way to be sure about the files consistency. (A matter of opinion)

    I used this method for over a year now and never had a checksum inconsistency after an upload.

    Excuse me for my english. It's not my native language. ^^