diff --git a/README.md b/README.md index 9726457..30b17e9 100644 --- a/README.md +++ b/README.md @@ -73,13 +73,15 @@ NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; ### File Upload with Progress Callback ``` objective-c +NSURL *url = [NSURL URLWithString:@"http://api-base-url.com"]; +AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5); -NSMutableURLRequest *request = [[AFHTTPClient sharedClient] multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id formData) { - [formData appendPartWithFileData:data mimeType:@"image/jpeg" name:@"avatar"]; +NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id formData) { + [formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"]; }]; AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease]; -[operation setUploadProgressBlock:^(NSUInteger totalBytesWritten, NSUInteger totalBytesExpectedToWrite) { +[operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) { NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite); }];