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

  • Home
  • SEARCH
  • 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 8728877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:43:50+00:00 2026-06-13T08:43:50+00:00

So I have a function which gets an image from a URL which looks

  • 0

So I have a function which gets an image from a URL which looks like this:

- (UIImage *) getImageFromURL:(NSString *)fileURL {
    UIImage * result;

    NSData * img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
    result = [UIImage imageWithData:img_data];

    return result;
}

and then a function which saves the image from a UIImage Which looks like this:

    -(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];
        NSLog(@"Image named %@ wrote to %@", imageName, directoryPath);
    } else {
        NSLog(@"Image Save Failed\nExtension: (%@) is not recognized, use (PNG/JPG)", extension);
    }
}

The issue I am facing is that when I run a UIImage through the saveImage function I dont think it is saving the image. This is because when I check for a UIImage imageNamed:@”Documents/filenamesavedas.jpeg” it returns (null). The image does however download correctly.

Here is my Documents Directory path function:

- (NSString *)getDocumentsDirectoryPath {
    NSString * documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSLog(documentsDirectoryPath);
    return documentsDirectoryPath;
}

Here is where I am downloading and trying to save the image:

   dispatch_async(jsonQueue, ^{
        // check to see if data authenticate runs successfully. 
    NSString *documentsDirectoryPath = [util getDocumentsDirectoryPath];
    UIImage *imageToSave = [util getImageFromURL:[properties objectForKey:@"current_group_logoURL"]];
    [util saveImage:imageToSave withFileName:[properties objectForKey:@"home_venue_logo"] ofType:@"jpeg" inDirectory:documentsDirectoryPath];
    NSLog(@"Group Logo URL %@", [properties objectForKey:@"current_group_logoURL"]);
    NSLog(@"Current Group Image %@", [properties objectForKey:@"home_venue_logo"]);        
        UIImage *testToSeeItHasDownloaded = imageToSave;
        NSString *imageLocation = [documentsDirectoryPath stringByAppendingPathComponent:[properties objectForKey:@"home_venue_logo"]];
        NSData *data = [NSData dataWithContentsOfFile:imageLocation];
        UIImage *testToSeeImageHasSaved = [UIImage imageWithData:data];
        NSLog(@"testToSeeImagehasDownloaded: %@", testToSeeItHasDownloaded);
        NSLog(@"image location to save to: %@", imageLocation);
        NSLog(@"testToSeeImagehasSaved: %@", testToSeeImageHasSaved );    

    });

The Console returns this:

2012-10-22 16:27:45.642 asdaf[46819:1d807] Group Logo URL http://somesite.com/50a0e42619424ba551a956511c098656.jpeg
2012-10-22 16:27:45.642 asdaf[46819:1d807] Current Group Image 50a0e42619424ba551a956511c098656.jpeg
2012-10-22 16:27:45.649 asdaf[46819:1d807] testToSeeImagehasDownloaded: <UIImage: 0xb09ed50>
2012-10-22 16:27:45.649 asdaf[46819:1d807] testToSeeImagehasSaved: (null)

testToSeeImagehasSaved should return null. But what am I doing wrong? Thanks.

  • 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-13T08:43:51+00:00Added an answer on June 13, 2026 at 8:43 am

    this line doesn’t look right to me:

    UIImage *testToSeeImageHasSaved = [UIImage imageNamed: [@"Documents/" stringByAppendingString: [properties objectForKey:@"home_venue_logo"]]];
    

    I think you have to do:

    UIImage* image = [UIImage imageWithContentsOfFile:"YOUR_FILE_PATH"];
    

    [UIImage imageNamed:"image_name"] is good only for images attached to your project

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

Sidebar

Related Questions

I have a function which looks something like this, it returns a noncopyable class
I have created a function which gets an encoded string (possibly UTF-16 not sure)
I am using jQuery(Latest release) and have a function called calculate() which gets called
I have a java code which gets the function names, their return types, their
I wrote one script which gets an image url through JSONP, and then I
I currently have the code below which successfully sets a random image from an
hi i have function which is called by tinker listbox so i cannot return
Can I´m asking for advice. I have function which should return javascript object function
I have a function which I have to loop it a few times but
I have a function which takes two arguments, the ID of an item (wine)

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.