MKNetworkKit file upload not working on iOS
I use MKNetworkKit perfectly for all my server requests. However, when trying to load an image file, it fails with this error:
Domain Error = NSURLErrorDomain Code = -1005 "The network connection was lost." UserInfo = 0x1010cb20 {NSErrorFailingURLStringKey = https://s3.amazonaws.com/net.myapp.upload, NSErrorFailingURLKey = https://s3.amazonaws.com/net.myapp.upload, NSLocalizedDescription = The network connection was lost., NSUnderlying = 0x1010ca60 "The network connection was lost.}
Sometimes the error code is 405. I have all the amazon credentials required to boot, and running cURL in a terminal with the same outgoing data as the application gives a correct return. The method I'm using for this request is here:
- (MKNetworkOperation*)uploadMediaFromFile:(NSString*)file urlCommand:(NSString*)url
postField:(NSString*)field authDict:(NSMutableDictionary*)authDict onCompletion:(
MediaUploadBlock)completionBlock onError:(MKNKErrorBlock)errorBlock {
MKNetworkOperation *op = [self operationWithURLString:url params:authDict
httpMethod:@"POST"];
[op addFile:file forKey:field];
// setFreezable uploads your images after connection is restored!
[op setFreezable:YES];
[op onCompletion:^(MKNetworkOperation* completedOperation) {
NSLog(@"%@",[completedOperation responseString]);
NSDictionary *jsonString = [completedOperation responseJSON];
NSLog(@"%@",jsonString);
completionBlock(jsonString);
}
onError:^(NSError* error) {
errorBlock(error);
}];
[self enqueueOperation:op forceReload:YES];
return op;
}
This is a fairly simple request that works from the terminal and works in the browser using the same parameters as here. I can't figure out why this doesn't work. Any help is appreciated.
source to share