I am trying to upload images to server with AFNetworking 3.0.
Here is my code :
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[[manager POST:setUrl parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData)
{
//Current date with image name
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss a"];
[formData appendPartWithFileData:image name:namePara fileName:[NSString stringWithFormat:@"img_%@",[dateFormatter stringFromDate:[NSDate date]]] mimeType:@"image/png"];
}progress:nil
success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject)
{
NSLog(@"%@",responseObject);
[GMDCircleLoader hideFromView:self.view animated:YES];
NSMutableDictionary *dir = [[NSMutableDictionary alloc]initWithDictionary:responseObject];
if([dir valueForKey:@"error"])
{
UIAlertController *alert = [[singletone sharedManager]showAlert:NSLocalizedString(@"SIGNIN", nil) :[NSString stringWithFormat: @"%@",[dir valueForKey:@"error"]] ];
[self.parentViewController presentViewController:alert animated:YES completion:nil];
}
else
{
//Successfull
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"REGISTRATION", nil) message:[dir valueForKey:@"success"] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * action)
{
[self.navigationController popViewControllerAnimated:YES];
}];
[alertController addAction:ok];
[self presentViewController:alertController animated:YES completion:nil];
}
NSLog(@"response object : %@",responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"failure : %@",error.localizedDescription);
}]resume];
It will get in success block with error : error In Image Uploading.
I have also tried from Postman to check my API response, but it's work fine from Postman. What is the problem with this code?