-1

代码可在https://github.com/dorian/magic

这样做时,image_tag image我得到:

您尝试访问的存储桶必须使用指定的端点进行寻址。请将所有未来的请求发送到此端点。

https://s3.amazonaws.com/magic.doma.io/iB68ze7FHdf8zYzoGrS4FzCP?response-content-disposition=inline%3B%20filename%3D%22Screen%20Shot%202018-04-06%20at%2011.19.32%20AM。 png%22%3B%20filename%2A%3DUTF-8%27%27Screen%2520Shot%25202018-04-06%2520at%252011.19.32%2520AM.png&response-content-type=image%2Fpng&X-Amz-Algorithm=AWS4- HMAC-SHA256&X-Amz-Credential=AKIAI4IE6Y56GAUDFDGQ%2F20180411%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180411T093708Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=c611a8262d6bc60467b3b4b3aa49be649407e1ce2264927c34b895fea75edb19

下面是我使用 ActiveStorage 的方法:

config/storage.yml

test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

amazon:
  service: S3
  access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
  secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
  region: us-east-1
  bucket: magic.doma.io

app/controller/ads_controller.rb

@ad.images.attach(ad_params[:images])

app/views/ads/show.html.slim

= image_tag image

app/views/ads/new.html.slim

= f.file_field :images, multiple: true

4

1 回答 1

0

我必须确保我使用的是正确的 aws 区域,例如us-east-2并在 AWS 上使用用户级访问密钥(而不是根密钥)。

于 2018-04-11T12:05:23.537 回答