Merge pull request #140 from houseoflegend/master
Updated "File Upload with Progress Callback" code snippet in README.md.
This commit is contained in:
commit
813df5f8a7
1 changed files with 5 additions and 3 deletions
|
|
@ -73,13 +73,15 @@ NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
|
||||||
### File Upload with Progress Callback
|
### File Upload with Progress Callback
|
||||||
|
|
||||||
``` objective-c
|
``` 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);
|
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5);
|
||||||
NSMutableURLRequest *request = [[AFHTTPClient sharedClient] multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
|
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
|
||||||
[formData appendPartWithFileData:data mimeType:@"image/jpeg" name:@"avatar"];
|
[formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
|
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);
|
NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue