开发者

Check if downloaded file is corrupted and delete if corrupted from iPhone

Problem: I have to download some files from the server. In between the connection with the server is lost. And when the file is opened it opened without any problem, except that it was blank.

Question How to check if the downloaded file from the server is corrupted or not? Is there any way to do that? If the file is corrupted it must be d开发者_开发百科eleted from the documents folder.

Thank you!


You can create a hash of the file and then use that hash to compare the current hash to the new hash.

Here's an example on creating a hash for iOS:

http://iosdevelopertips.com/core-services/create-md5-hash-from-nsstring-nsdata-or-file.html

It should work pretty well because the hash only changes if the file contents change and is unaffected by creation times, modification times, and the file name.

Edit You can also sign your files with PGP or GPG and use your public key to verify its contents.

Hope this helps :)


Send a hash of the file with the file, and then compare the hashes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜