Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone base64 corrupted when posted to php script
    primarykey
    data
    text
    <p>In my app the user crops there picture i encode it to a base64 string and send it to my php script.I am using the NSData+base64 class However, when the app goes to retrieve the string again to convert back into a picture I get this error:</p> <pre><code>Jan 8 14:21:33 Vessel.local Topic[11039] &lt;Error&gt;: ImageIO: JPEG Corrupt JPEG data:214 extraneous bytes before marker 0x68 Jan 8 14:21:33 Vessel.local Topic[11039] &lt;Error&gt;: ImageIO: JPEG Unsupported marker type 0x68 </code></pre> <p>Here is the code in which i send off the data:</p> <pre><code> NSString *urlString = [NSString stringWithFormat:@"http://myurl.php"]; NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; [request setHTTPMethod:@"POST"]; NSString *param = [NSString stringWithFormat:@"username=%@&amp;password=%@&amp;email=%@&amp;quote=%@&amp;pic=%@",user,password,email,quote,pic]; [request setHTTPBody:[param dataUsingEncoding:NSUTF8StringEncoding]]; NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES]; </code></pre> <p>Here is when i get it back in another view controller and attempt to turn it back into a image</p> <pre><code> -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ homeData = [NSJSONSerialization JSONObjectWithData:responseData options:nil error:nil]; NSString *decodeString = [[homeData objectAtIndex:0]objectForKey:@"profile_pic" ]; decodeString = [decodeString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; int returnNUM = [decodeString length]; NSLog(@"RETURN STRING=%d",returnNUM); NSData *data = [[NSData alloc] initWithData:[NSData dataFromBase64String:decodeString]]; profilepic = [[UIImageView alloc]initWithFrame:CGRectMake(5, 4, 120, 120)]; profilepic.image = [UIImage imageWithData:data]; UIGraphicsBeginImageContextWithOptions(profilepic.bounds.size, NO, 1.0); [[UIBezierPath bezierPathWithRoundedRect:profilepic.bounds cornerRadius:80.0] addClip]; [pic drawInRect:profilepic.bounds]; profilepic.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self.view addSubview:profilepic]; } </code></pre> <p>How can i prevent the image from being corrupted once i post it..or once i get it back how can i clean it or prevent the corruption thats happening! This is driving me nuts..a clear answer with some code would be highly appreciated.Thanks</p> <p>This is the code that I use to convert the image into base64 before i send it.</p> <pre><code> NSData *imageData = UIImageJPEGRepresentation(crop, 1.0); NSString *baseString = [imageData base64EncodedString]; int original =[baseString length]; NSLog(@"orignal String=%d",original); [self register:username.text withPass:password.text withEmail:email.text withQuote:quote.text withPic:baseString]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload