3

Carrierwaveを使用してファイルをアップロードしています。OS X 10.8を実行している開発マシンでは、ファイルをアップロードして、期待どおりにファイルをダウンロードできます。私が見る開発ログのテーリング:

Started GET "/resources/download_file/11" for 127.0.0.1 at 2013-03-24 06:29:33 -0400
Processing by ResourcesController#download_file as HTML
  Parameters: {"id"=>"11"}
  Resource Load (0.2ms)  SELECT "resources".* FROM "resources" WHERE "resources"."id" = ?     LIMIT 1  [["id", "11"]]
Sent file     /Users/scervera/rails_apps/mdn/public/uploads/resource/document/11/MyDocument.pdf (0.1ms)
Completed 200 OK in 2ms (ActiveRecord: 0.2ms)

Capistranoを使用してUbuntu12.04サーバーVMにデプロイした後、ファイルをアップロードできます(そして、ファイルがサーバー上に物理的に存在することを確認します)が、リンクをクリックしてファイルをダウンロードすると、次のメッセージが表示されます。

「ファイル「MyDocument.pdf」は空であるため開くことができませんでした。」

Production.logをテーリングすると、次のようになります。

Started GET "/resources/download_file/1" for 192.168.0.90 at 2013-03-24 06:31:12 -0400
Processing by ResourcesController#download_file as HTML
  Parameters: {"id"=>"1"}
Sent file     /var/mdnapp/releases/20130322184251/public/uploads/resource/document/1/MyDocument.pdf (0.1ms)
Completed 200 OK in 2ms (ActiveRecord: 0.1ms)

このSQL行が欠落していることに注意してください。

Resource Load (0.2ms)  SELECT "resources".* FROM "resources" WHERE "resources"."id" = ? 

ファイルを開こうとしたところ、実際には空です。

また、deploy.rbに以下を追加しようとしましたが、これは役に立ちましたが、この特定の問題は解決しませんでした。

set :shared_children, shared_children + %w{public/uploads}

追加の詳細 download_fileというメソッドを持つresources_controllerがあります。下記参照:

def download_file
  @resource = Resource.find(params[:id])
  send_file(@resource.document.path,
        :type => 'application/pdf',
        :disposition => 'attachment',
        :url_based_filename => true)
end

私の見解では、このメソッドを呼び出すリンクタグがあります。以下のビューコードを参照してください。

<% if @resources.empty? %>
    <p>There are no resources available at this time.</p>

<% else %>
    <% @resources.each do |resource| %>

    <div class="resource_wrap clearfix">
            <h1><%= resource.title.html_safe %></h1><h2><%= resource.subtitle.html_safe %></h2>
        <p><%= image_tag resource.image_url(:wallet).to_s %><%= resource.description.html_safe %></p>

        <div id="attachments">
            <% if resource.document? %>
                <p>Get the resource:<%= link_to 'Download File', :action => 'download_file', :id => resource.id %></p>
            <% end %>
            <% if resource.video? %>
                <p>Get the video:<%= link_to 'Download Video', :action => 'download_video', :id => resource.id %></p>
            <% end %>
        </div>
    </div>
    <% end %>
<% end %>

Rails 3.2.11、Ruby 1.9.3p194、Carrierwave 0.8.0、rmagick2.13.2を実行しています

さらに詳しい情報が必要な場合はお知らせください。

4

1 に答える 1

3

わかった。私は問題を理解しました。config / environment / Production.rbファイルを編集して、次の行をコメントアウトする必要がありました。

config.action_dispatch.x_sendfile_header = "X-Sendfile"

これを研究するのに多くの時間を費やしました。他の誰かが恩恵を受けることができることを願っています。

于 2013-03-27T22:02:12.220 に答える