开发者

Would redirect_to rather than send_file deliver better perceived rendering time when using Paperclip and S3?

开发者 https://www.devze.com 2023-03-15 04:42 出处:网络
I have an app that lives in the Heroku ecosystem and it uses paperclip\'s S3 storage mechanism. Have any of you conducted performance tests of using send_file vs. redirect_to when sending file data vi

I have an app that lives in the Heroku ecosystem and it uses paperclip's S3 storage mechanism. Have any of you conducted performance tests of using send_file vs. redirect_to when sending file data via a controller action? To be specific:

class ImagesController < ApplicationController

  def show
    @image = Image.find_by_name(params[:name])
    render :nothing => true, :status => 404 and return if missing_source(@image)
    respond_to do |format|
      format.html { send_file(@image.source.to_file.path,
                              :type => @image.source_content_type,
             开发者_如何学编程                 :disposition => 'inline') }
      format.xml  { render :xml => @image }
    end
  end


  private

    def missing_source(image)
      image.nil? || !image.source.exists?
    end

end

My question is, would it be "better" to use

redirect_to @image.source.url

instead of

send_file(@image.source.to_file.path,
          :type => @image.source_content_type,
          :disposition => 'inline') 

With send_file, it seems pclip requests the file from S3, saves the file temporarily on the local filesystem, then sends it to the browser. With redirect_to, the controller simply issues 3xx responses to the client.


well, the send_file defeats the whole purpose of using s3... you'll be using the app server to serve the file. Use the redirect

0

精彩评论

暂无评论...
验证码 换一张
取 消