Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:28:34+00:00 2026-06-13T12:28:34+00:00

I have an array url image from Json. I want to download, save and

  • 0

I have an array url image from Json.

I want to download, save and display images inside app. Check image exist in app.

Can you help me!

Thank in advance

code download,save and display: -> I don’t know check image exist
Use it:

for (int i=0; i<[self.imageURLs count]; i++) {
        if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"img%d.jpg",i]]) {
            NSLog(@"file exists at the path");
        }
        else
            NSLog(@"file doesnt exist");

        int y_lblLogo = i==0 ? 45 : (20 * (i+1)) - 15 ;
        UIImage * imageFromURL = [self getImageFromURL:[self.imageURLs objectAtIndex:i]];

        [self saveImage:imageFromURL withFileName:[NSString stringWithFormat:@"img%d",i] ofType:@"png" inDirectory:documentsDirectoryPath];

        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(200 * i, 0, 100, 100)];
        UIImage * imageFromWeb = [self loadImage:[NSString stringWithFormat:@"img%d",i] ofType:@"png" inDirectory:documentsDirectoryPath];
        imgView.image = imageFromWeb;

        [imgView drawRect:CGRectMake(0,y_lblLogo,70.f,30.f)];
        //[self.view addSubview:imgView];
    }

    -(UIImage *) getImageFromURL:(NSString *)fileURL {
              UIImage * result;
             NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
            result = [UIImage imageWithData:data];
             return result; 
    }

    -(void) saveImage:(UIImage *)image withFileName:(NSString *)imageName ofType:(NSString *)extension inDirectory:(NSString *)directoryPath {
             if ([[extension lowercaseString] isEqualToString:@"png"]) {
                [UIImagePNGRepresentation(image) writeToFile:[directoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@",
          imageName, @"png"]] options:NSAtomicWrite error:nil];
              } else if ([[extension lowercaseString] isEqualToString:@"jpg"] || [[extension lowercaseString] isEqualToString:@"jpeg"]) {
                 [UIImageJPEGRepresentation(image, 1.0) writeToFile:[directoryPath stringByAppendingPathComponent:[NSString
          stringWithFormat:@"%@.%@", imageName, @"jpg"]] options:NSAtomicWrite
         error:nil];
             } else {

            } 
    }

     -(UIImage *) loadImage:(NSString *)fileName ofType:(NSString *)extension inDirectory:(NSString *)directoryPath {
              UIImage * result = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.%@", directoryPath, fileName, extension]];
              return result; 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:28:35+00:00Added an answer on June 13, 2026 at 12:28 pm

    Here is complete code you need:

    - (UIImage *)imageFromURL:(NSString*) surl fromCache:(BOOL)fromCache
    {
    UIImage *img;
    if(surl!=nil && [surl compare:@""]!=NSOrderedSame) {
        NSString* key = [self getFilenameFromUrl:surl];
        NSData *data = [self getDataFromURL:surl fromCache:fromCache];
        if(data) {
            img = [[UIImage alloc] initWithData:data];
        }
    }
    return img;
    }
    
    -(NSString*) getFilenameFromUrl:(NSString*) surl
    {
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^a-zA-Z0-9\\._]"
                                                                           options:NSRegularExpressionCaseInsensitive
                                                                             error:nil];
    return [regex stringByReplacingMatchesInString:surl options:0 range:NSMakeRange(0, [surl length]) withTemplate:@"_"];
    }
    
    -(NSString*) getCacheFolder {
        NSFileManager *filemgr = [NSFileManager defaultManager];
        NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *sDocumentsDir = [documentPaths objectAtIndex:0];
        sDocumentsDir = [sDocumentsDir stringByAppendingPathComponent:@"/.tmp"];
        BOOL isDir;
        if(!([filemgr fileExistsAtPath:sDocumentsDir isDirectory:&isDir] && isDir))
        {
            [filemgr createDirectoryAtPath:sDocumentsDir withIntermediateDirectories:YES attributes:nil error:nil];
        }
        return sDocumentsDir;
    }
    
    -(NSData *) getDataFromURL:(NSString*) surl fromCache:(BOOL) fromCache
    {
        NSData *urlData;
    
        if(surl!=nil && [surl compare:@""]!=NSOrderedSame) {
            surl = [surl stringByReplacingOccurrencesOfString:@" " withString:@"20"];
            NSFileManager *filemgr = [NSFileManager defaultManager];
            NSString *furl = [NSString stringWithFormat:@"%@/%@",[self getCacheFolder],[self getFilenameFromUrl:surl]];
    
            if (fromCache && [filemgr fileExistsAtPath: furl]==YES) {
                //NSLog (@"File exists");
                urlData = [filemgr contentsAtPath: furl];
            } else if([self hasConnection]){
                //NSLog (@"File not found");
                [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
                NSURL  *url = [NSURL URLWithString:surl];
                NSError *err;
                urlData = [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:&err];
                if (!err && urlData)
                {
                    [filemgr createFileAtPath: furl contents: urlData attributes: nil];
                } else {
                    NSLog(@"%@",err);
                }
                [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            }
        }
    
        return urlData;
    }
    

    also, to display you might use some existing component, like FGallery, for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a requirement, i want to take URL of image from user and
I have an array built from the URL of a webpage. If an item
So I have an array that's being pulled from a json object that I'd
Android:How to display images from the web in a ListView?I have the following code
Say I have a JSON string like: {title:aaa,url:bbb,image:{url:ccc,width:100,height:200}, ... My accessor: import com.google.gson.annotations.SerializedName; public
I have array of image in scroll view. I want to upload bigger image
I’m new to android,I have an activity class which fetches Json string from url
I have a function that retrieves some images from a JSON feed using NSURLConnection.
I have an array of URL Links that I'm trying to load into a
I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.