Image content not getting converted to NSData

Discussion in 'iOS Programming' started by AbhishekApple, Dec 1, 2010.

  1. AbhishekApple macrumors member

    Joined:
    Aug 5, 2010
    #1
    Please suggest for this.....

    I am facing a strange problem....
    the following code converts data of only one image from the list of images and rest of the images it finds null..
    (i checked with the images they are all present on the server )
    (I did tested the app on device am facing same issue)

    Code:
    for (NSString *name in imagesArray){
    
    NSLog(@"%@",name);
    NSString *imgPath=[NSString stringWithFormat:@"http://www.abc.com/images/thumbnails/%@",name];
    NSData *imageData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imgPath]];
    NSLog(@"ImageData=%@",imageData);
    UIImage *thumbImage = [UIImage imageWithData:imageData];
    [imageData release];
    .....
    .....
    ....
    }
    
    Heres the output i am getting

    And some times i am getting this error,,,,,,
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    I'm not sure why it's not working, but you shouldn't be downloading like this as it's a synchronous process and cannot be canceled. Instead use NSURLConnection and download asynchronously.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    I think "abc.com" was used as a fake name. The OP should have used "example.com".


    Just because a file is on a server doesn't mean it's accessible to HTTP requests.

    A simple test is to paste the complete URL of the image into the address bar of any browser, and see if it can retrieve the image from the server. If a browser can retrieve it, then the iphone app should be able to retrieve it, too. There's no magic here: it's just an HTTP request and reply. If you get 404 Not found responses (or 3xx redirects, or anything other than a 200 OK), then you need to fix something outside of the iphone app.

    A better test is to watch what's actually happening on the network when the iphone program runs. Tools that do this are called "traffic watchers" or "packet sniffers". One such tool is WireShark:
    http://www.wireshark.org/download.html

    Interarchy 8 also had traffic watching ability, but it's gone from recent Interarchy versions.
     
  5. AbhishekApple thread starter macrumors member

    Joined:
    Aug 5, 2010
    #5
    (abc.com is jst an example)
    And yes the actual url didn't retrieved the images as the "name" which i was retrieving had a leading space because of which it was getting null
    like http://www.example.com/images/ 10.jpg

    Same old problem
    Thanks a lot for reminding
     

Share This Page