LoginSignup
0
0

More than 3 years have passed since last update.

Rails5.2でIEでもリンクを保存せずに直接開けるようにする

Last updated at Posted at 2020-08-27

railsでPDFをsend_dataしているリンクが、IE11では保存の選択肢しかでず、不思議に思っていたら
Rails5.2リリースノートの変更点 https://railsguides.jp/5_2_release_notes.html
にありました。

セキュアなX-Download-OptionsおよびX-Permitted-Cross-Domain-Policiesをデフォルトのヘッダーセットに追加。 (Commit)

デフォルトでは、脆弱性を突いたファイルをいきなりアプリで開かないようにとの意図かと思うのですが、試したブラウザの中では皆スルーされている中で、IE11だけ「保存しかできない」状態になるのが意外というかなんというか。(いろいろ誤解している可能性あり)

そこでIE11でも直接開きたい場合は例えばこんな感じ。

        response.headers["X-Download-Options"] = nil (if ...リスク許容条件...)
        send_file(file_path,:filename => filename,:type=>content_type,:disposition=>'inline')

サイト全体適用ならconfigでもできるのかも。
→ コメントで対応例を教えていただきました。

cinfig/application.rb
config.action_dispatch.default_headers.delete('X-Download-Options')
0
0
2

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
0
0