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 339261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:30:23+00:00 2026-05-12T10:30:23+00:00

I have a folder on my remote server that has a few .png files

  • 0

I have a folder on my remote server that has a few .png files in it. I want to download these from within my app and store them in the apps ‘Documents’ folder. How can I do this?

  • 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-05-12T10:30:24+00:00Added an answer on May 12, 2026 at 10:30 am

    The easy way is to use NSData’s convenience methods initWithContentOfURL: and writeToFile:atomically: to get the data and write it out, respectively. Keep in mind this is synchronous and will block whatever thread you execute it on until the fetch and write are complete.

    For example:

    // Create and escape the URL for the fetch
    NSString *URLString = @"http://example.com/example.png";
    NSURL *URL = [NSURL URLWithString:
                  [URLString stringByAddingPercentEscapesUsingEncoding:
                              NSASCIIStringEncoding]];
    
    // Do the fetch - blocks!
    NSData *imageData = [NSData dataWithContentsOfURL:URL];
    if(imageData == nil) {
        // Error - handle appropriately
    }
    
    // Do the write
    NSString *filePath = [[self documentsDirectory] 
                          stringByAppendingPathComponent:@"image.png"];
    [imageData writeToFile:filePath atomically:YES];

    Where the documentsDirectory method is stolen shamelessly from this question:

    - (NSString *)documentsDirectory {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);
        return [paths objectAtIndex:0];
    }

    However, unless you intend to thread it yourself this will stop UI activity while the file downloads. You may instead want to look into NSURLConnection and its delegate – it downloads in the background and notifies a delegate about data downloaded asynchronously, so you can build up an instance of NSMutableData then just write it out when the connection’s done. Your delegate might contain methods like:

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
        // Append the data to some preexisting @property NSMutableData *dataAccumulator;
        [self.dataAccumulator appendData:data];
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
        // Do the write
        NSString *filePath = [[self documentsDirectory] 
                              stringByAppendingPathComponent:@"image.png"];
        [imageData writeToFile:filePath atomically:YES];
    }

    The little details, like declaring the dataAccumulator and handling errors, are left to the reader 🙂

    The important documents:

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

Sidebar

Related Questions

I have an application that is loading html from a remote server in a
I have a folder called Etc which has an image I want to use
I have an ASP.NET MVC 3 app that is using SQL Server CE 4.0
I want to create a post build script that moves files from the build
I have a page on a server at a remote location that only displays
I have a folder with multiple files, and I'd like to remove all <script>
I have folder on which i want to apply security like the current user
We have a folder where our app will be potentially reading, writing and creating/deleting
I have a folder full of 100-odd Access97 files. I need to update them
I'm using JSch to get files from an SFTP server, but I'm trying to

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.