I am totally new to iOS.I want to upload images to my server using AFNetworking. I tried it but it still not done. Please Help me, thanks in advance
Asked
Active
Viewed 3,715 times
4
-
possible duplicate of [Uploading image with AFNetworking 2.0](http://stackoverflow.com/questions/19836432/uploading-image-with-afnetworking-2-0) – Abubakr Dar Feb 25 '15 at 10:24
-
You should google before asking questions, there are many answers to your questions in other posts. – Abubakr Dar Feb 25 '15 at 10:24
-
i tried it but using that answer i am not able get answer using that, its generates error – Yagnesh Dobariya Feb 25 '15 at 10:47
-
You should tell the error – Abubakr Dar Feb 25 '15 at 14:52
1 Answers
5
try with this its work for me
-(void) uplodeImages{
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"url where to upload images"]];
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"cat1.png"]);
NSDictionary *parameters = @{@"username": @"", @"password" : @""};
AFHTTPRequestOperation *op = [manager POST:@"cat1.png" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//do not put image inside parameters dictionary as I did, but append it!
[formData appendPartWithFileData:imageData name:@"userfile" fileName:@"cat1.png" mimeType:@"image/png"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@ ***** %@", operation.responseString, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@ ***** %@", operation.responseString, error);
}];
[op start];
}

Sachin Patil
- 353
- 1
- 13
-
-
-
@Septronic nice ans but i have a ques if you can help me out ..can i send **image(with key)**, **audio file(with key)** and string values (dict parameters) together using this code ..? **please help if you little time** – vaibhav May 26 '16 at 11:52