How to fix the same file content when uploading files

Source: Internet
Author: User
Tags md5 encryption

Now there is a requirement: when uploading files, all uploaded files, as long as the content is the same, only in the server to save a copy.

How do I compare file contents? If the mind was constrained at the time, it was hard to think of a way to compare file contents.

Workaround:

File upload, it must be used to read the file stream, the same source of file content is: Stream read out the same byte code. This thought of the solution, but the problem came again. How do I compare byte codes? It is not a good solution to think of such a long bytecode, if compared with the Equals method of the string. After some thinking, I decided to stream read out the bytecode for MD5 encryption, with the encrypted string as the file name , and then in the file upload (the same file content, the natural file name is the same, and then automatically covered), so that the need to solve.

  

How to fix the same file content when uploading files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.