0

我有一个rails 3.0.3网站,在开发模式下,通过调用didReceiveData,然后connectionDidFinishLoading响应HTTP GET,并将照片数据从网站发送到iPhone和正确显示。但是,当我在Amazon Web Services上以生产模式运行rails 3.0.3网站时,在didReceiveData之前调用connectionDidFinishLoading。我使用carrierwave处理开发和生产rails站点的照片。connectionDidFinishLoading之前调用didReceiveData与rails生产发送照片

有没有人有任何想法可能会导致connectionDidFinishLoading在didReceiveData之前调用?

我试着检查以下内容:

1)我确定NSURLConnectionDelegate被调用这个类的接口。

2)didReceiveResponse不会被调用之前connectionDidFinishLoading和的StatusCode = 200

3)在我使用由send_file发送的照片数据的Rails应用程序,并在生产中发送的文件的路径,是一张实际的照片。

4)通过对网站的完整请求进行检查,结果显示使用下面的代码在connectionDidFinishLoading中生成网站返回了0字节的数据(结果证明didReceiveData没有被调用) :

NSData *returnedData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://production_website"]]; 

这里是didReceiveData代码:

// theConnectionData is an instance variable defined as: 

     NSMutableData *theConnectionData = [[NSMutableData data] retain]; 


-(void)connection:(NSURLConnection *)con didReceiveData: (NSData *)data { 

[theConnectionData appendData:data ]; 

} 

更新 - 我想这个问题可能是在铁轨上的一面。下面是我用从Rails应用程序从本地存储在AWS将照片发送到iPhone应用程序的代码:

@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 
       ) 

任何人都有的,为什么didReceiveData是没有得到connectionDidFinishLoading的导轨生产网站之前叫什么想法?

+0

它应该工作..但我们不能测试你的代码。如果你可以提供didReceiveData的代码。 – 2012-02-28 03:21:27

+0

请注意,didReceiveData被rails的开发版本调用,但不会被生产版本的rails调用。 – 2012-02-28 13:23:36

+0

你可以给生产网站的地址,以便我可以测试...它可能是你的网站的问题,而不是在生产模式下的iPhone编码 – 2012-02-28 14:21:50

回答

0

我终于明白了。注释掉配置/环境以下/ production.rb固定的问题:

# config.action_dispatch.x_sendfile_header = "X-Sendfile" 

问题也固定通过用替换配置/环境/ production.rb上述行以下操作:

config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" 

根据这post它看起来像Rails 3对send_file的一些变化。此post建议使用X-Accel-Redirect方法,但是该帖子声称该请求是从rails应用程序发送的,而不是从nginx发送的。 post声称nginx需要X-Accel-Redirect方法。