LoginSignup
0
0

More than 3 years have passed since last update.

Active Storageでファイルアップロード時に403エラー

Posted at

現象

Active StorageでS3にファイルアップロードした際に以下のエラーダイアログを表示し、エラー。
3回に1回くらいの割合で失敗しているため、CORSやパーミッションのエラーではない。

  Error storing "ファイル名.pdf". Status: 403

Chrome Developer ToolsのNetworkタブ

  Request URL: 割愛(ActiveStorageのurl_forヘルパー押下により作成されたリンク)
  Request Method: PUT
  Status Code: 403 Forbidden
  Remote Address: XXX.XXX.XXX.XXX:443
  Referrer Policy: strict-origin-when-cross-origin

環境

  • Ruby 2.7.0
  • Rails 6.0.2.1
  • Active Storage 6.0.2.1
  • S3

原因

セキュリティ対策として、S3の署名付きURLの有効期限を1秒にしていたことが原因と思われる。

active_storage.rb
  Rails.application.config.active_storage.service_urls_expire_in = 1.second

対応

有効期限を適切に(今回は10秒)変更した。

active_storage.rb
  Rails.application.config.active_storage.service_urls_expire_in = 10.second
0
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
0
0