您尝试访问的存储区必须使用指定的端点进行处理

时间:2018-04-11 09:47:55

标签: ruby-on-rails rails-activestorage

代码位于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

1 个答案:

答案 0 :(得分:0)

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