I'm uploading files to Dropbox, and I'm wondering if I can mark anything through NSFileManager to test to see whether a file has already been uploaded. I've been combing through the documentation and haven't found anything yet that could help.
So for instance, if I've uploaded a file called song.m4a, and the user changes the name of that file in the app, how would I be able to find out whether that file has been uploaded with the new name so that the file doesn't get uploaded again?
Are there any properties or attributes I could set to see if the file has been uploaded?
Thanks.
You can use hashing, eg you can calculate the MD5 hash of the file and store it in a local file on the phone, when the user tries to upload a file, you don't check its name, you simply recalculate the MD5 hash and check if it exists in your local file, if it does, then it was uploaded once before.
Edit:
You can convert anything to NSData and then calculate the hash of that NSData, eg in your case you can load the file like this
NSData* data = [NSData dataWithContentsOfFile:yourFilePath];
then you can hash it like this
- (NSString*)MD5:(NSData*)input
{
// Create byte array of unsigned chars
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
// Create 16 byte MD5 hash value, store in buffer
CC_MD5(input.bytes, input.length, md5Buffer);
// Convert unsigned char buffer to NSString of hex values
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x",md5Buffer[i]];
return output;
}
and don't forget to import
#import <CommonCrypto/CommonDigest.h>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.