I got this Base64 gif image:
R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmN
Code snippet for downloading a text file with base64 image string inside, then saving/reading the file and finally creating an image to display right in the view
In Case You Need To Decode Image To Base64 Click Here
NSString *downloadUrl = "http://www.server.com/file.txt";
//
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: downloadUrl]];
//
// DOWNLOAD THE FILE
//
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if (error) {
NSLog(@"Download Error:%@",error.description);
}
if (data) {
[data writeToFile:filePath atomically:YES];
//
// PROCESS BASE 64 STRING
//
NSString * fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
//
// PROCESS BASE 64 STRING
//
NSString *base64String = fileContents;
NSURL *url = [NSURL URLWithString:base64String];
NSData *imageData = [NSData dataWithContentsOfURL:url];
//
// CREATE IMAGE
//
UIImage *ret = [UIImage imageWithData:imageData];
self.myImage.image = ret;
}
}