How to convert UIImage to base64 and POST to URL

It is difficult for me to convert the image to base64, and then send it to the server, where I will get the number in response. I am using target c.

Any ideas? I tried a couple of things, but when I try to set some NSDictionary parameters, I always get an error.

+4
source share
3 answers

Convert UIImage to 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 line in the usual way and publish to the server. You also need to make small changes to your server to get this image.

+4
source

Convert UIImage string to base64 For target c

NSData *imageData = UIImageJPEGRepresentation(_profileImgObj.image, 1.0);
NSString *base64Img = [imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];

For swift

let Imagedata = UIImageJPEGRepresentation(_profileImgObj.image, 0.5)
let strBase64Image = Imagedata!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions())
+3
source

Swift:

let data = UIImageJPEGRepresentation(image, 0.5)
let imageString = data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros)
+2

Source: https://habr.com/ru/post/1606239/


All Articles