From fee500c445785554fa5859136471548355492f3e Mon Sep 17 00:00:00 2001 From: Larry Legend Date: Sun, 4 Dec 2011 13:41:10 -0500 Subject: [PATCH] Updated "File Upload with Progress Callback" code snippet in README.md. - Resolved a mismatch between variable names imageData and data. - Updated to the current appendPartWithFileData:name:fileName:mimeType: method signature. - Updated to the current upload progress block signature ^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {...} - Added two lines that create an ad-hoc AFHTTPClient instance, instead of referencing a hypothetical [AFHTTPClient sharedClient] singleton, which new users might be confused by when they're trying to get the example working. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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); }];