LoginSignup
1
0

More than 1 year has passed since last update.

carrierwaveでS3にアップロードしたファイルをダウンロード

Last updated at Posted at 2021-05-23

コード

Companyモデルにsample_csvという名前のカラムがある想定。

ダウンロードされるファイル名がsample.csvになるように設定している。

<%= link_to 'サンプルCSVをダウンロード', @company.sample_csv.url(query: { 'response-content-disposition' => "attachment; filename=sample.csv" }).to_s %>

このリンクをクリックするとブラウザにファイルがダウンロードされる。

リクエストした先のアクションでsend_dataを使う実装だとメモリを使ってサーバーに負荷をかけてしまうが、このやり方はRailsアプリケーションにリクエストを送らないのでサーバに負荷をかけないのがメリット。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0