I have a rails 3.0.3 website that, in development mode, responds to a HTTP GET by calling didReceiveData and then connectionDidFinishLoading, and photo data is sent from the website to the iPhone and displayed correctly. But when I run the rails 3.0.3 website in production mode on Amazon Web Services, connectionDidFinishLoading is called before didReceiveData. I'm using carrierwave to handle the photos for both the development and production rails sites.
Does anyone have any idea what could cause connectionDidFinishLoading to get called before didReceiveData?
I've tried checking the following:
1) I made sure the NSURLConnectionDelegate is called for the class' interface.
2) didReceiveResponse doesn't get called before connectionDidFinishLoading and the statusCode = 200.
3) In the rails app I am using send_file to send the photo data, and the path to the file sent in production, is an actual photo.
4) Checking with the full request to the website showed that 0 bytes of data was being returned from the production website by using the code below in connectionDidFinishLoading (this turned out to be the reason that didReceiveData wasn't being called):
NSData *returnedData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://production_website"]];
Here is the code for didReceiveData:
// theConnectionData is an instance variable defined as:
NSMutableData *theConnectionData = [[NSMutableData data] retain];
-(void)connection:(NSURLConnection *)con didReceiveData: (NSData *)data {
[theConnectionData appendData:data ];
}
Update - I'm thinking the problem might be on the rails side. Here is the code I use to send a photo from the rails app from local storage on AWS to the iPhone app:
@p = Photo.find_by_user_id(user_id)
uploader = @p.avatar
uploader.retrieve_from_store!(File.basename(@p.avatar.url))
uploader.cache_stored_file!
send_file(uploader.file.path,
:disposition => 'inline',
:encoding => 'binary',
:type => @p.content_type,
:stream => false,
:filename => URI.encode(@p.filename),
:x_sendfile => true,
:buffer_size => 16384
)
Anyone have any idea of why didReceiveData is not getting called before connectionDidFinishLoading for the rails production website?