Skip to content

Instantly share code, notes, and snippets.

@dkasper
Created December 18, 2012 00:29
Show Gist options
  • Save dkasper/4323786 to your computer and use it in GitHub Desktop.
Save dkasper/4323786 to your computer and use it in GitHub Desktop.
Testing code for afnetworking bug
-(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