1

We're currently using Active Storage to upload avatar images to Amazon S3 which is working great on local as well as production

class User < ApplicationRecord
  has_one_attached :avatar
end

I'm now trying to use Action Text and followed the directions on Rails Guides which is working perfectly on localhost

class Course < ApplicationRecord 
  belongs_to :user
  has_rich_text :content
end

When I deploy to production, however, the rich text formatting works but attachments are not being uploaded to S3 which surprised me since I assumed it's using the same active storage credentials that we used for the avatar image uploads. Strangely it's populating the active_storage_blobs table with the filenames even though they are not being uploaded or being referenced by active_storage_attachments.

Could someone help?

vince
  • 2,374
  • 4
  • 23
  • 39
  • need your production.rb & gemfile. did you go through https://edgeguides.rubyonrails.org/active_storage_overview.html ? – Yshmarov Oct 12 '20 at 23:02

2 Answers2

3

In order to configure CORS on AWS, you need to change the settings for your production bucket.

An example CORS configuration, in JSON, would look like so:

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "https://www.example.com"
        ],
        "ExposeHeaders": []
    }
]

Where https://www.example.com is the URL of your Rails app. Make sure you do not allow all origins (which you would do by replacing the URL with the * wildcard).

bumcode
  • 362
  • 4
  • 13
0

Turns out the default is direct uploads in Action Text (unlike Active Storage attachments) and it works after setting up CORS on S3

vince
  • 2,374
  • 4
  • 23
  • 39