Created
December 18, 2012 00:29
-
-
Save dkasper/4323786 to your computer and use it in GitHub Desktop.
Testing code for afnetworking bug
This file contains 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
-(void)testImageUpload { | |
NSString *url = [NSString stringWithFormat:@"/photos/index.json"]; | |
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://localhost:3000"]]; | |
NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { | |
//100 bytes of data | |
NSString *seed = @"iauhsdoifusdoiusfsduyxctzivytcixhudsifnlekjrnjewrbfkuydgvyuqewbemnfdbfsoiddfhdalufhasdlnqeiuqeuwbfux"; | |
NSMutableArray *seeds = [NSMutableArray arrayWithCapacity:654]; | |
for(int i=0; i<653;i++) { | |
[seeds addObject:seed]; | |
} | |
[seeds addObject:@"asdfasdfasasdfasdfasasdfasdfasasdfasdfasasdfasdfasasdfasdfasasdfasdfasasdfasdfas"]; | |
NSString *dummyString = [seeds componentsJoinedByString:@""]; // total of 65380 chars, with the headers the data segments add up to 65536 bytes | |
NSData *dummyData = [dummyString dataUsingEncoding:NSUTF8StringEncoding]; | |
NSLog(@"DUMMY DATA LENGTH IS %d", dummyData.length); | |
[formData appendPartWithFileData:dummyData name:@"image" fileName:@"IMG_159.JPG" mimeType:@"image/jpeg"]; | |
}]; | |
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { | |
NSLog(@"success"); | |
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { | |
NSLog(@"error"); | |
}]; | |
[operation start]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment