artifacts/AFCache — Issue #12: Error was code: 63 - message: File name too long
Author: reallylongaddress
Created: 2011-10-09 16:15:01+00:00
State: open

Hi there...

Been playing with your AFCache and got the above error (My urls are pretty darn long). So here's my hack/fix...do as you wish with it:

2011-10-09 09:57:45.091 MobileIgniter[7629:207] Error: could not create file "/Users/dominic/Library/Application Support/iPhone Simulator/4.0.2/Applications/99347D6D-885F-4E87-9D6B-7F553CC96062/Library/Caches/com.mobileigniter.proofofconcept.tropicana/localhost:8888/modules/index.php/listDetail/?signed_request=8mIgkXSbpKrxnKdIM1moOzTN66oFqSukvgwkS_HltWs.eyJ0aXRsZSI6IlRyb3BpY2FuYSBEZWFscyIsIm1vZHVsZV9rZXkiOiJsaXN0X2RldGFpbF9tb2R1bGVfa2V5IiwibW9kdWxlX2luc3RhbmNlX2tleSI6IndrbXozMjh2MGtubGFydmM4ZTM5ZzVkbGZtcjJqYzI2In0&system_name=iPhone%20OS&system_version=4.0.2"

2011-10-09 09:57:45.098 MobileIgniter[7629:207] Error was code: 63 - message: File name too long

----SO I shortened the url part of the filename via MD5-----
- (NSString *)filePathForURL: (NSURL *) url {

NSLog(@"dataPath: %@", dataPath);
NSLog(@"filenameForUrl: %@", [self filenameForURL: url]);

//dbd let's md5 the url else we get an error (Error was code: 63 - message: File name too long)
NSString *hashedFilename = [StringUtils returnMD5Hash:[self filenameForURL: url]];

NSLog(@"hashedFilename: %@", hashedFilename);

NSLog(@"before/after %i/%i", [[self filenameForURL: url] length], [hashedFilename length]);

return [dataPath stringByAppendingPathComponent:hashedFilename];
}

----WHERE MD5 generated via---
//generate md5 hash from string
+ (NSString *) returnMD5Hash:(NSString*)concat {
const char *concat_str = [concat UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(concat_str, strlen(concat_str), result);
NSMutableString *hash = [NSMutableString string];
for (int i = 0; i < 16; i++)
[hash appendFormat:@"%02X", result[i]];
return [hash lowercaseString];

}

Best,
Dominic