Here i am trying to sent image to server side but its giving me error
if(picking)
{
NSLog(@"entering in to image side");
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"content-Disposition:form-data;name=\"pic\"\r\n\r\n filename=imageName.jpg\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:picking]];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
}
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[body length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
dispatch_async(dispatch_get_main_queue(),^{
if([data length]>0 && connectionError==nil)
{
NSError *error;
NSMutableDictionary *jsonResponse=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
if(error){
[Utitlity alertFunction:@"Warning" message:[error localizedDescription]];
}
else
{
[self requestComplete:jsonResponse];
}
}
this image present in sign up screen,if i didn't select picture in sign up screen means ,customer registration getting success.while select image its give cocoa 3048 error.
Issue is in your below statement. Per Apple documentation NSJSONReadingMutableContainers
option should be used for arrays and dictionaries. Please try with NSJSONReadingAllowFragments
.
NSMutableDictionary *jsonResponse=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
Constants NSJSONReadingMutableContainers Specifies that arrays and dictionaries are created as mutable objects.
Available in iOS 5.0 and later. NSJSONReadingMutableLeaves Specifies that leaf strings in the JSON object graph are created as instances of NSMutableString.
Available in iOS 5.0 and later. NSJSONReadingAllowFragments Specifies that the parser should allow top-level objects that are not an instance of NSArray or NSDictionary.
Available in iOS 5.0 and later.