Created
February 12, 2014 06:46
-
-
Save paingpyi/8951025 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AFHTTPRequestOperationManager.h" | |
#import "AFURLSessionManager.h" | |
- (void)uploadImage | |
{ | |
NSError *error; | |
NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"$2y$1UW3CKMNTe",@"TOKEN_KEY", | |
@"1",@"userId", | |
@"lovely dog",@"animalName", | |
@"2",@"categoryId", | |
nil]; | |
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://162.243.203.150/api/v1.1/post" parameters:param constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { | |
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"banner_sub.jpg"], 0.7); | |
NSData *imageData2 = UIImageJPEGRepresentation([UIImage imageNamed:@"bedok_logo.jpg"], 0.7); | |
NSData *imageData3 = UIImageJPEGRepresentation([UIImage imageNamed:@"bleach.jpeg"], 0.7); | |
[formData appendPartWithFileData:imageData name:@"photos[0]" fileName:@"banner_sub.jpg" mimeType:@"image/jpeg"]; | |
[formData appendPartWithFileData:imageData2 name:@"photos[1]" fileName:@"bedok_logo.jpg" mimeType:@"image/jpeg"]; | |
[formData appendPartWithFileData:imageData3 name:@"photos[2]" fileName:@"bleach.jpeg" mimeType:@"image/jpeg"]; | |
} error:&error]; | |
NSLog(@"%@",error); | |
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; | |
NSProgress *progress = nil; | |
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { | |
if (error) { | |
NSLog(@"Error: %@", error); | |
} else { | |
NSLog(@"%@ %@", response, responseObject); | |
} | |
}]; | |
[uploadTask resume]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment