Objective-C
Objective-C
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat Objective-C Downloads
#import <CkoFileAccess.h>
#import <NSString.h>
BOOL success = NO;
// Get the contents of a file into a base64 encoded string:
CkoFileAccess *fac = [[CkoFileAccess alloc] init];
NSString *strBase64 = [fac ReadBinaryToEncoded: @"c:/data/something.pdf" encoding: @"base64"];
if (fac.LastMethodSuccess != YES) {
NSLog(@"%@",fac.LastErrorText);
return;
}
// Now write the string to a file:
success = [fac WriteEntireTextFile: @"c:/data/something_pdf_base64.txt" fileData: strBase64 charset: @"us-ascii" includePreamble: NO];
if (success != YES) {
NSLog(@"%@",fac.LastErrorText);
return;
}
NSLog(@"%@",@"Success!");