This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2712|Reply: 0

[Other] The frontend uses spark-md5 to calculate the file MD5 value

[Copy link]
Posted on 4/30/2024 5:31:55 PM | | | |
Requirements: Many websites will have file upload requirements, such as uploading avatars, uploading resources, etc. In order to ensure the integrity and consistency of the file, the front-end usually calculates the MD5 value of the file and submits it to the back-end when uploading.

js to get the MD5 value of the file
https://www.itsvse.com/thread-7296-1-1.html

Hash (MD5 Verification Tool) V1.04 Installation-Free Version
https://www.itsvse.com/thread-4035-1-1.html

crypto-js calculates the sha256 value of the file
https://www.itsvse.com/thread-7293-1-1.html


SparkMD5 is a fast md5 implementation of the MD5 algorithm. The script is based on the JKM md5 library, which is the fastest algorithm. This works best for browsers because the nodejs version is probably faster.

GitHub address:The hyperlink login is visible.
Compressed version of the js package:The hyperlink login is visible.

When calculating the MD5 value of a file using the browser, by using chunk calculations,If the file is relatively large, using FileReader to load it into memory at one time will cause the browser to crash or freeze and become unresponsive

Test a 235 MB file as shown below:




The code is as follows:





Previous:JS reverts the HTML entity encoding
Next:ASP.NET MVC uses Autofac to add global filters
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com