ArtStyle ArtStyle - 1 year ago 65
iOS Question

Sending base64 from Objective-C app to PHP server

My current Objective-C code

UIImage *image = self.selectedImage;
NSData *data = [UIImagePNGRepresentation(self.selectedImage)

NSString *byteArray = [NSString stringWithUTF8String:[data bytes]];
NSMutableURLRequest *request =
[[NSMutableURLRequest alloc] initWithURL:
[NSURL URLWithString:@"http://API URL IS HERE "]];

[request setHTTPMethod:@"POST"];

NSString *postString = [NSString stringWithFormat:@"id_user=%ld&id_from_user=%@&content=%@&type=photo",(long)_userIdTo,[[NSUserDefaults standardUserDefaults] valueForKey:@"id_user"],byteArray];
NSLog(@"strin %@", postString);

[request setHTTPBody:[postString

send image's byte-code to the server in the base64 form.

If I try to paste the byte-code in Chrome’s plugin for API (Google rest advanced) in the browser, I get an image.
But if I try to send it through the app, I had a black square, or nothing, instead the image.

Any ideas?

Answer Source

It could be the NSDataBase64Encoding64CharacterLineLength option adding line breaks which I'm not sure PHP supports. Try passing 0 instead and see if PHP can decode the string.