NSMutableDictionary *files = [[NSMutableDictionary alloc] init];
UIImage *imageFromImageView = userpic.image;
NSData *data1 = UIImageJPEGRepresentation(imageFromImageView, 0.8);
if ([data1 length]>0) {
[files setValue:data1 forKey:@"photo"];
}
NSString *urlString =@"http://chkdin.com/dev/api/user/update_user?";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *parameterString=[NSString stringWithFormat:@"skey=%@&user_id=%@&first_name=%@&last_name=%@&designation=%@&company=%@&display_name=%@&photo=%@",@"XXXXXXXX",[[NSUserDefaults standardUserDefaults]objectForKey:@"UserId"],FirstNameString,LastNameString,DesignationString,OrganizationString,displayname,files];
NSLog(@"%@",parameterString);
[request setHTTPMethod:@"POST"];
[request setURL:url];
[request setValue:parameterString forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSData *postData = [parameterString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:postData];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
[activityIndicatorView stopAnimating];
} else {
NSLog(@"%@ %@", response, responseObject);
}
}];
[dataTask resume];
This is I tried code, here user selected image I upload to server but image is not uploading. Here user selected image I converted to file formate then I send to server. Can you please help me what is the issue in my code.