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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:57:19+00:00 2026-05-22T02:57:19+00:00

Attempting to download multiple files from an XML feed. There are several Categories and

  • 0

Attempting to download multiple files from an XML feed. There are several Categories and each category has an unknown amount of images. I create a subdirectory for each category, no problem. When I try to download each file to the respective category, every file is written with the same data for every image there is in the feed.

I guess my question is how can I download 1 file at a time to the corresponding directory without overwriting all of the images with the same data?

-(void)parsingComplete:(XMLDataSource*)theParser 
{
    /*  iterate through the Categories and create the 
        sub-directory if it does not exist  
     */

    for (int i = 0; i < [categories count]; i++) 
    {
        NSString *cat      = [NSString stringWithFormat:@"%@/%@",BASE_DIR,[[categories objectAtIndex:i] objectForKey:@"name"]];
        NSString *catName  = [[categories objectAtIndex:i] objectForKey:@"name"];
        NSArray  *catArray = [[categories objectAtIndex:i] objectForKey:@"images"];

        /*  create the sub-direcotry naming it the #category# key  */
        if (![FILEMANAGER fileExistsAtPath:cat]) {
            [FILEMANAGER createDirectoryAtPath:cat withIntermediateDirectories:NO attributes:nil error:nil];
        }

        //NSLog(@"\n\nCategory: %@",cat);
        for (int x = 0; x < [catArray count]; x++) 
        {
            /*  download each file to the corresponding category sub-directory  */

            fileOut = [NSString stringWithFormat:@"%@/%@_0%i.jpg",cat,catName,x];

            NSURLRequest * imageRequest = 
            [NSURLRequest requestWithURL:[NSURL URLWithString:[[catArray objectAtIndex:x] objectForKey:@"imageUrl"]]
                             cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
            [[NSURLConnection alloc] initWithRequest:imageRequest delegate:self];
        }
    }
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection  
{  
    [receivedData writeToFile:fileOut atomically:YES];
} 
  • 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-22T02:57:20+00:00Added an answer on May 22, 2026 at 2:57 am

    Yes, this is what I mentioned in my comment. Each time connectionDidFinishLoading: is called, you’ve got the result of just one connection. If you loop through all the file names, you will write that same chunk of data out to all those names, repeatedly. Each time through the for loop in parsingComplete: you create a new connection, get a new data object, and then write that same object out multiple times. After the end of the parsing... loop, you’re left with a list of files all with the data from the last connection.

    I’m pretty tired and I’m not sure: am I being clear?


    Addressing your comment:

    You’ll either have to make the correct file name for the current connection available to the delegate methods, probably by putting it in an ivar, or go the synchronous route. Putting in it in some ivar like currFileName so that all the methods in this class can access it is probably the least painless way to get the job done.

    /* In parsingCompleted: */
    for (int x = 0; x < [catArray count]; x++) 
    {
        /*  download each file to the corresponding category sub-directory  */
        // fileOut is an instance variable
        fileOut = [NSString stringWithFormat:@"%@/%@_0%i.jpg",cat,catName,x];
        imageRequest = [NSURLRequest etc...
    

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
        // No loop; just use that file name that you set up earlier; 
        // it correctly corresponds to the current NSURLConnection
        [receivedData writeToFile:fileOut atomically:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to download fairly large files (up to, possibly over 1GB) from
I am attempting to download a lot of files from http://www.sl.universalservice.org/funding/opendatasearch/Search1.asp using the Python
I am attempting to trigger a download of an XML file stream from a
I am attempting to download a gunzipped file from an FTP server. It appears
I'm attempting to download an external mp3 into internal storage. However, the files I'm
I'm currently using a HttpResponse to download files from my Server. I already have
I am attempting to setup a webdav website for various clients to upload/download files.
I'm attempting to pull in data from Google's Shopping API. I'm able to download
I am attempting to load each url in a sitemap.xml file in an effort
I am attempting to download images saved in a url to a local folder,

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.