0

我正在使用ActionText 使用image_processinggem 上传图像。但是,在上传图像时,它们不会转到 Active Storage 中设置的 S3。

所有其他图像上传工作正常,并按预期进入我的 S3 存储桶。它只是上传到不使用 S3 URL 的 ActionText 编辑器的图像。但是,它们确实进入了正确的存储桶。这只是我无法在blob元素中更改或访问的 URL。

我假设在初始化程序或配置中有一个我无法找到的设置,但我无法通过文档或谷歌找到它。

Blob 当前使用的 URL 是rail/active_storage/存储 URL,我需要它来使用我在 active_storage.yml 文件中设置的 S3 URL。

4

1 回答 1

0

原来我可以编辑_blob.html.erb文件中的 URL。首先,我必须检查我是否在生产中。一旦我确认我能够使用blob.key.

  <% if blob.representable? %>
    <% if Rails.env == 'production' %>
      <img class: "post-actiontext-image" src="https://<%= ENV['S3_BUCKET'] %>.s3-<%= ENV['AWS_REGION'] %>.amazonaws.com/<%= blob.key %>" />
    <% else %>
      <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]), class: "post-actiontext-image" %>
    <% end %>
  <% end %>
于 2020-06-14T16:26:15.743 回答