2014-09-23 30 views
0

我試圖通過控制器方法顯示使用由send_file

class DocumentsController < ApplicationController 
    def show 
    response.headers['X-Sendfile-Type'] = "X-Sendfile" 
    send_file(@document.file.path, filename: @document.file.name, type: "application/pdf", disposition: :inline) 
    end 
end 

這個本地工作精細顯示上傳PDF文件PDF,但在Heroku我得到的隱性應用程序錯誤,沒有進一步的堆棧跟蹤

at=info method=GET path="/documents/21" host=myapp.herokuapp.com request_id=754f6d15-cb06-43a1-aa3c-308e5308b54e fwd="76.21.40.212" dyno=web.1 connect=29ms service=27ms status=500 bytes=1543 

我已經嘗試在config/environments/production.rb中設置config.action_dispatch.x_sendfile_header = "X-Sendfile",但這會導致應用程序上的所有資產都無法在生產環境中加載。

我錯過了什麼?

回答

1

報價Heroku's documentation(重點煤礦):

Heroku的不支持使用機櫃的:: SENDFILE。機架:Sendfile通常要求有一個像nginx這樣的前端Web服務器,或者apache與應用程序服務器在同一臺機器上運行。這不是Heroku如何構建的。

serve static files and uploads from a Heroku app,最好的辦法是使用一個服務如Amazon S3存儲:架構的大規模應用時

AWS S3,或類似的存儲服務,是重要的,是一個完美的補充Heroku的臨時文件系統。

+3

夠公平的。有沒有辦法在heroku上顯示文件? – 2014-09-23 06:25:11