0

I have an application where I am sending image data on server through ftp and retrieving back in a functionality of preview. Now I am able to send the image on server,but while retrieving it back,I am getting following error in NSData and 0 bytes are fetched.

Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn\u2019t be completed. (Cocoa error 256.)"

I am parsing data through XML and fetching the image url like this

http://111.222.333.44/abc/images/User/img102-13.png

Now,when I use the following code to retrieve imgstr to nsdata, but getting the above error in the same.

 NSURL *u = [NSURL URLWithString:imgstr];
 NSError *error;
 NSData *dt = [NSData dataWithContentsOfURL:u options:NSDataReadingMapped error:&error];
 myImage = [UIImage imageWithData:dt];

I am able to fetch other data easily,but not the image data. Can anybody point out,where I am doing mistake or how I can resolve the problem? Thanks in advanced.

EDIT : In my application I am first of all capturing an image and storing it on the server. And then on the 2nd page,I need to fetch the image data and to show the same image when the user clicks a button called Preview. I am having a web service where I am getting the data including the path of the image as shown above,but with the method shown I am not able to fetch the Image data in NSData and getting the Cocoa error 256. Hope this help someone to show me a better and correct Path. Thanks.

1 Answer 1

0

I think the problem with this approach is that it will block the UI thread until the image is downloaded.

try to load that image in separate thread.

Well i tried your code and i too have a webService that takes the image from a url.

instead of doing the above code. you can directly do try this:

    NSURL *u=[NSURL URLWithString:imgstr];
    UIImage *image1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:u]];

In my case its working.

If you are still struck then the below link might help you:

http://blog.beefyapps.com/2010/03/coredata-sqlite3-database-constraint-failed-error/

2
  • Thanks Ajeet,but what i can say is I am new to the technology and I also tried the method NSData *dt = [NSKeyedArchiver archivedDataWithRootObject:u]; but this method is also not fetching any data. Can you guide me with some other way,if you are aware of the same?
    – Yama
    Nov 29, 2011 at 6:20
  • I tried your code but it still fails. And following your link,it shows that the problem might be with the database side. So I need to handle it from that part,i guess. Anyways,will let you know if it works in that manner or not. Thank you for the link.
    – Yama
    Nov 29, 2011 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.