robert robert - 9 months ago 60
iOS Question

How to convert UIImage to base64 and POST to URL

I'm having difficult with converting an image to base64 and then posting it to a server, where I will receive a number in return. I am using objective c.

Any ideas? I've tried a couple of things but I always get a thread error when trying to set certain NSDictionary parameters.


Convert UIImage in base64

NSData *imageData = UIImageJPEGRepresentation(uploadImage, 1.0);
NSString *base64String = [imageData base64EncodedStringWithOptions:kNilOptions];
NSString *encodedString2 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( NULL,  (CFStringRef)base64String,    NULL,   CFSTR("!*'();:@&=+$,/?%#[]\" "),   kCFStringEncodingUTF8));

send this string using normal way and post on server. Also need to minor changes on your server to getting this image.