0

我们目前正在使用 Active Storage 将头像图像上传到 Amazon S3,这在本地和生产环境中都表现出色

class User < ApplicationRecord
  has_one_attached :avatar
end

我现在正在尝试使用 Action Text 并遵循Rails Guides上的说明,该说明在 localhost 上运行良好

class Course < ApplicationRecord 
  belongs_to :user
  has_rich_text :content
end

然而,当我部署到生产环境时,富文本格式有效,但附件没有上传到 S3,这让我感到惊讶,因为我认为它使用的活动存储凭证与我们用于上传头像图像的活动存储凭证相同。奇怪的是,它active_storage_blobs使用文件名填充表,即使它们没有被上传或被active_storage_attachments.

有人可以帮忙吗?

4

2 回答 2

1

为了在 AWS 上配置 CORS,您需要更改生产存储桶的设置

JSON 格式的 CORS 配置示例如下所示:

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

https://www.example.com您的 Rails 应用程序的 URL在哪里。确保您不允许所有来源(您可以通过将 URL 替换为*通配符来实现)。

于 2021-09-03T18:52:22.790 回答
0

结果默认是操作文本中的直接上传(与活动存储附件不同),它在 S3 上设置 CORS 后工作

于 2020-10-13T17:04:55.237 回答