1

My current Objective-C code

UIImage *image = self.selectedImage;
NSData *data = [UIImagePNGRepresentation(self.selectedImage) 
    base64EncodedDataWithOptions:NSDataBase64Encoding64CharacterLineLength];

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
                      dataUsingEncoding:NSUTF8StringEncoding]];

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.