Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 Streaming multiple images with x_sendfile hangs under Tomcat
    text
    copied!<p>I have a little app in JRuby on rails 3.x that needs to return user images stored in the file system outside the public folder. I thought that using a separate controller to respond to these requests would be the best way to retrieve them. It works fine with 2 or 3 images, but on a page displaying more than 6 or 7 images it returns 5 or so and then stalls out. The rest of the images never appear. I read somewhere that it may not be closing the response properly, but to be honest I don't know what that means or how to fix it. The app runs fine under webrick, but when deployed to Tomcat as a WAR file (created by warbler) it exhibits this behaviour. It's like Tomcat can't handle all the simultaneous requests. After the first few images are returned the browser will sit ans spin for a few minutes waiting for more images and then give up. If I hit the 'page stop loading' button I find that I can't navigate to another page, like Tomcat is still tied up.</p> <p>In routes.rb I have:</p> <pre><code>match '/serve_image/:account/:user/:file' =&gt; 'images#serve' </code></pre> <p>My image controller code is very simple:</p> <pre><code>class ImagesController &lt; ApplicationController def serve path = "#{Rails.application.config.cir}/#{params[:account]}/#{params[:user]}/#{params[:file]}" send_file( path, :disposition =&gt; 'inline', :type =&gt; 'image/jpeg', :x_sendfile =&gt; true ) end end </code></pre> <p>In the erb file it's called with:</p> <pre><code> &lt;img class="porto_image" alt="image" src="&lt;%=porto_image.image_filename.html_safe%&gt;" /&gt; </code></pre> <p>porto_image relevant code:</p> <pre><code>def image_filename ret = "#{Rails.application.config.cir_web_prefix}serve_image/#{account}/#{user}/#{self.image_file}" ret end </code></pre> <p>So, any idea why this only works for a couple images but falls on it's face when I throw 10-20 image calls at it from the same page?</p> <p>Any help greatly appreciated, this one has me stumped &amp; blocked.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload