Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 285
robert Avatar asked Jan 08 '23 15:01

robert


1 Answers

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.

like image 78
Jogendra.Com Avatar answered Jan 16 '23 06:01

Jogendra.Com