简体   繁体   English

文件上传完整性检查

[英]file upload integrity check

I have file uploads in a form like photo or some other documents. 我以照片或其他一些文件的形式上传文件。 Sometimes the file get uploaded ie,the file path will be there but the size will be 0 bytes or a part file. 有时文件会被上传,例如,文件路径将存在,但大小为0字节或部分文件。 Please suggest me a solution to check the complete integrity check for such uploads. 请提出一个解决方案,以检查此类上传的完整完整性。 I have one solution to find the file size and check it after upload complete, is this a reliable solution?, any other good methods? 我有一个解决方案,可以找到文件大小并在上传完成后进行检查,这是一种可靠的解决方案吗?还有其他好的方法吗?

Finding the size is not a completely reliable solution. 找到尺寸并不是一个完全可靠的解决方案。 I would recommend you to use checksum for checking the integrity of file transferred. 我建议您使用校验和检查传输文件的完整性。 Client should calculate the checksum of file it is sending, send the checksum value with the request as a param. 客户端应计算其发送文件的校验和,并以请求为参数发送校验和值。 On the server side, again checksum should be calculated and compared against the checksum sent by the client. 在服务器端,应再次计算校验和,并将其与客户端发送的校验和进行比较。 If two matches, file is good! 如果两个匹配,文件就好!

Here is a sample to generate checksum in java: 这是在Java中生成校验和的示例:

http://www.mkyong.com/java/how-to-generate-a-file-checksum-value-in-java/ http://www.mkyong.com/java/how-to-generate-a-file-checksum-value-in-java/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM