Image content not getting converted to NSData

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

  1. AbhishekApple macrumors member

    Aug 5, 2010
    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)

    for (NSString *name in imagesArray){
    NSString *imgPath=[NSString stringWithFormat:@"",name];
    NSData *imageData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imgPath]];
    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


    Jun 15, 2000
    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


    Staff Member

    Sep 2, 2004
    The Centennial State
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    I think "" was used as a fake name. The OP should have used "".

    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:

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

    Aug 5, 2010
    ( 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 10.jpg

    Same old problem
    Thanks a lot for reminding

Share This Page