How to get the image from the base64encodedstring ?

I am using base64encoding for sending an UIImage to the server and then on the other end i am getting it back, converting the base64encodedstring in to NSData then trying to get my image back on an UIImageView.

Everything working fine sending the Base64encodedString and receiving it but when i am converting the NSData back in to UIImage it is throwing the following exception

-[__NSArrayI dataUsingEncoding:allowLossyConversion:] exception is comming with Base64 encoding

this is the code i am using for posting the image:

img=mainImage.image;
NSData *imgdata=UIImagePNGRepresentation(img);
NSString *imgstring=[imgdata base64EncodedString];
NSString *post =[[NSString alloc] initWithFormat:@"gid=%@&image=%@",[lblgid text],imgstring];
NSLog(@"PostData: %@",post);

NSURL *url=[NSURL URLWithString:@"http://www.abcd/updategameimage.php"];

And following is the code at receiving end

 NSString *imgStr=[abc valueForKey:@"image"];
    NSLog(@"%@",imgStr);
    NSData *imgdata=[NSData dataWithBase64EncodedString:imgStr];


    imge = [UIImage imageWithData:imgdata];

    [imgview setImage:imge];

Here abc is NSMutableArray

Answers


Are you sure abc is a mutableArray?

Because you are sending it a valueForKey: method. This is a KVC method implemented by NSObject and it doesn't make sense to send it this message.

If you meant to send it the objectForKey: method instead - then that would be a message that you send to dictionaries, not arrays.

And, the error that you are getting:

-[__NSArrayI dataUsingEncoding:allowLossyConversion:] exception is comming with Base64 encoding

is telling you that an NSArray does not respond to dataUsingEncoding:allowsLossyConversion: messages - which is a method for NSString objects.

I think you are getting confused with your object types and need to get a better handle on what is what.


Need Your Help

RTSP server stream camera

mfc live555

I'm working with RTSP server and camera user MFC, I must stream camera and the client will use VLC to watch camera in real time.

boost::serialization high memory consumption during serialization

serialization memory boost consumption

just as the topic suggests I've come across a slight issue with boost::serialization when serializing a huge amount of data to a file. The problem consists of the memory footprint of the serializa...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.