AFNetworking/AFNetworking — Issue #130: appendPartWithFileURL:name:error: loads file into memory
Author: alexzielenski
Created: 2011-11-27 02:55:02+00:00
State: open

My problem is with the method below. It loads the file into NSData and then sends the file. I don't think this is a good practice. Instead, it should send the file in increments. This is of concern to me because it makes my application hang while loading a medium sized file into memory. (64mb+)
```
- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error {
if (![fileURL isFileURL]) {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:fileURL forKey:NSURLErrorFailingURLErrorKey];
[userInfo setValue:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey];
if (error != NULL) {
*error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease];
}

return NO;
}

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fileURL];
[request setCachePolicy:NSURLCacheStorageNotAllowed];

NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:error];

if (response && !error) {
[self appendPartWithFileData:data name:name fileName:[response suggestedFilename] mimeType:[response MIMEType]];

return YES;
} else {
return NO;
}
}
```